Recent

Author Topic: Dynamicaly assigning methods  (Read 7369 times)

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
Dynamicaly assigning methods
« on: November 14, 2004, 03:48:29 pm »
I have a problem. I'm creating a dynamic button (for example like that:
Code: [Select]
var MyButton: TButton;
...
MyButton:=TButton.Create(Self);
MyButton.Top:=2;
MyButton.Left:=2;
MyButton.Width:=200;
MyButton.Height:=28;
MyButton.Caption:='MyButton';
)
And now how to assign a method to a dynamic button? Such thing should work:
Code: [Select]
MyButton.OnClick:=MyForm.MyButtonClick;
Unfortunately, it doesn't do anything except halting compilation and calling an error: Wrong number of parameters... Of course, compiler is trying to assign a return value of MyButtonClick method. How to solve this problem??

mikiwoz

  • Full Member
  • ***
  • Posts: 130
Dynamicaly assigning methods
« Reply #1 on: November 14, 2004, 08:05:19 pm »
MyButton.OnClick:=@WhateverIsTheMethodsName should do the trick. I had the same problem and that was the solution.

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
Dynamicaly assigning methods
« Reply #2 on: November 14, 2004, 10:45:38 pm »
Unfortunately, it ends with an error: Incopatible types: got "<address of procedure(TObject) of Object;Register>" expected "<procedure variable type of procedure(TObject) of Object;Register>" :(

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Dynamicaly assigning methods
« Reply #3 on: November 15, 2004, 09:32:20 am »
This might be a compiler bug. What compiler version are you using?

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
Dynamicaly assigning methods
« Reply #4 on: November 15, 2004, 10:01:37 am »
I'm using FPC 1.9.5 (2004/10/04). Should I change it??

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2583
Dynamicaly assigning methods
« Reply #5 on: November 15, 2004, 05:44:13 pm »
is TObject redeclared ? (are you still using {$mode objfpc} )
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
Dynamicaly assigning methods
« Reply #6 on: November 15, 2004, 07:17:19 pm »
{$mode objfpc} is in every main program. Shouldn't it?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2583
Dynamicaly assigning methods
« Reply #7 on: November 19, 2004, 02:54:36 pm »
afaik in every unit
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018