Recent

Author Topic: type TPutItemIDEvent = procedure (Sender: TObject; ItemID: integer; Code: string  (Read 2524 times)

Rieske1969

  • Newbie
  • Posts: 3
Hello there,

I am new to Lazerus but done some great development with Delphi a few years ago.
What I'm trying to do is create a simular type of application as I did with Delphi 7 but I'm running in to some problems.

There a two form, Main.pas and Settings.pas.
Settings.pas is called via a Button on Main.pas and I want to give a notification back from Settings.pas to Main.pas.

In Delphi I did it as follows:

Main.pas
-------------------------
private
   procedure PutItemSearchEvent(Sender: TObject; ItemID: integer; Code: string);

procedure TfrMain.PutItemSearchEvent(Sender: TObject; ItemID: integer; Code: string);
begin

end;

Settings.pas
--------------------------
type TPutItemIDEvent = procedure (Sender: TObject; ItemID: integer; Code: string) of object;


private
    { private declarations }
    fOnPutItemIDEvent : TPutItemIDEvent;
public
    { public declarations }
    property OnPutItemIDEvent: TPutItemIDEvent read fOnPutItemIDEvent write fOnPutItemIDEvent;


When I call the settings form there is an event that is instanced to a local procedure.

  frSettings := TfrSettings.Create(self);
  frSettings.OnPutItemIDEvent:= PutItemSearchEvent;
  frSettings.Visible := false;
  frSettings.ShowModal;
  frSettings := nil;

In Settings.pas I can give the parameters: Sender, ItemID and Code back to Main.pas.

In Delphi this worked but in Lazerus I get the following error: 'main.pas(56,33) Error: Wrong number of parameters specified for call to "PutItemSearchEvent"'


What am I doing wrong?


Richard


howardpc

  • Hero Member
  • *****
  • Posts: 4144
You probably have {$mode objfpc}


So you have to explicitly use the @ operator:
Code: Pascal  [Select][+][-]
  1.  frSettings.OnPutItemIDEvent:=@PutItemSearchEvent;
  2.  


or use {$mode delphi}
« Last Edit: December 26, 2015, 11:06:05 pm by howardpc »

Rieske1969

  • Newbie
  • Posts: 3
Wow, that was quick (and painless)

Thanks.

 

TinyPortal © 2005-2018