[fpc-pascal] got "untyped" expected "<procedure variable type of procedure(TObject) of object; Register>"

Howard Page-Clark hdpc at talktalk.net
Wed Jul 16 10:07:08 CEST 2014


On 15/07/2014 19:56, rupert THURNER wrote:

> type
>    TForm1 = class(TForm)
>      procedure SpeedButton1Click(Sender: TObject);
>
> procedure TForm1.SpeedButton1Click(Sender: TObject);
>
> procedure TForm1.CreateButton(t: Integer;l: Integer;btext: String; machine:
> String);
> var
>    button: TSpeedButton;
> begin
>    button:=TSpeedButton.Create(self);
>    button.OnClick:=SpeedButton1Click(button);

There are two errors.

button should be a field in the TForm1 class. Declared as a local 
variable it will be inaccessible after CreateButton() exits.

If using {$mode objfpc} the OnCick assignment should be

button.OnClick:=@SpeedButton1Click;

with no parameter specified. In delphi mode you don't need the "@" operator.

Howard




More information about the fpc-pascal mailing list