Problem defining onClick in Runtime with Pascal (Delphi/Lazarus)

Asked

Viewed 732 times

1

I need to use the procedure ClicaItem(Sender: TObject); in a OnClick created at runtime by the procedure CriaItem(nome:String);. However, in all my attempts, I could not attribute item.OnClick à Procedure ClicaItem. How should I proceed if there is a mistake concerning the incomparable types?

Error: Incompatible types: got address of Process (Tobject);Register" expected "Process variable type of Project (Tobject) of Object;Register>"

I ask to clarify the creation of the process to the type accepted by Onclick, and how should I do this assignment in the event OnClick.

NOTE: The item is normally created in Runtime (runtime), but the line referring to Onclick is commented due to the error before compiling.

  • You cannot assign one directly to the other because they have different parameters. I think more information than you’re willing to be able to do is important.

1 answer

2


Your Clicaitem process must belong to an instance of a class (object);

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
     procedure ClicaItem(Sender: TObject);
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
   Button1.Click := ClicaItem;
end;

procedure TForm1.ClicaItem(Sender: TObject);
begin
   ShowMessage('ClicaItem');
end;

end.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.