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

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Jul 16 11:04:04 CEST 2014


On 15/07/14 20:56, rupert THURNER wrote:

> var
>    button: TSpeedButton;
> begin
>    button:=TSpeedButton.Create(self);
>    button.OnClick:=SpeedButton1Click(button);
>    // gives error:
>    // unit1.pas(121,19) Error: Incompatible types: got "untyped" expected
> "<procedure variable type of procedure(TObject) of object;Register>"

You are calling the function SpeedButton1Click here (with the parameter 
"button") and trying to assign its result to button.OnClick. Since 
SpeedButton1Click is a procedure, it does not return a value (= "void"), 
hence the error message.

What you want/need to do instead, is assign the address of the 
SpeedButton1Click procedure to button.OnClick. How this is done, depends 
on the syntax mode. In ObjFPC mode (the default in Lazarus), it's 
"button.OnClick:=@SpeedButton1Click;". In Delphi mode, it's 
"button.OnClick:=SpeedButton1Click;".


Jonas




More information about the fpc-pascal mailing list