Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-07

got "untyped" expected "<procedure variable type of procedure(TObject) of object; Register>"

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

rupert THURNER

hi,

what am i doing wrong with lazarus 1.2.2 to get the error "untyped" expected "<procedure variable type of procedure(TObject) of object;Register>", see below when assigning "OnClick".

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);
  // gives error:
  // unit1.pas(121,19) Error: Incompatible types: got "untyped" expected
"<procedure variable type of procedure(TObject) of object;Register>"

regards,

rupert

Reply by email

Howard Page-Clark
to rupert THURNER
rupert THURNER wrote 13 lines
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

;

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

Howard

Reply by email

Jonas Maebe
to rupert THURNER: what am i doing wrong with lazarus 1.2.2 to get the error "untyped" expected "<procedure…
rupert THURNER wrote 8 lines
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 ";". In Delphi mode, it's
"button.OnClick:=SpeedButton1Click;".

Jonas

Reply by email

Marco van de Voort
to Howard Page-Clark: There are two errors. button should be a field in the TForm1 class. Declared as a local…

In our previous episode, Howard Page-Clark said:

Show quoted text 8 lines
> 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.

(he passes self as owner, so strictly speaking it will be accessable via the form. But indeed it is not common practice.)

Reply by email