Dynamicaly assigning methods lazarus / 8-Other ---------------------------------------------------------------------- Adam.Pilorz · 2004-11-14 14:48 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 · 2004-11-14 19:05 MyButton.OnClick:=@WhateverIsTheMethodsName should do the trick. I had the same problem and that was the solution. ---------------------------------------------------------------------- Adam.Pilorz · 2004-11-14 21:45 Unfortunately, it ends with an error: Incopatible types: got "
" expected "" ---------------------------------------------------------------------- Vincent Snijders · 2004-11-15 08:32 This might be a compiler bug. What compiler version are you using? ---------------------------------------------------------------------- Adam.Pilorz · 2004-11-15 09:01 I'm using FPC 1.9.5 (2004/10/04). Should I change it?? ---------------------------------------------------------------------- Marc · 2004-11-15 16:44 is TObject redeclared ? (are you still using {$mode objfpc} ) ---------------------------------------------------------------------- Adam.Pilorz · 2004-11-15 18:17 {$mode objfpc} is in every main program. Shouldn't it? ---------------------------------------------------------------------- Marc · 2004-11-19 13:54 afaik in every unit