Sorry, I know that this is a already disccussed argument, but I really need a tip because I'm not able to understand what I'm doing wrong.
I created a unit
WITHOUT any form (so no class exists), to put inside all necessary code to dynamically create a new form with some components, one of them is a button, and obviously I want to assign a procedure to this button.
This unit will be used from other units that have a form, by insert "UnitFormDeluxeAbout" into uses, and calling the procedure "CreateFormDeluxeAbout" and assigning tha calling form as parent.
My test code is this:
unit UnitFormDeluxeAbout;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Buttons, StdCtrls;
procedure CreateFormDeluxeAbout(form_parent: TForm);
implementation
var
DeluxeFormAbout: TForm;
DeluxeFormAboutCloseButton: TButton;
procedure DeluxeFormAboutCloseButtonClick(Sender: TObject); forward;
procedure CreateFormDeluxeAbout(form_parent: TForm);
begin
DeluxeFormAbout := TForm.Create(form_parent);
DeluxeFormAbout.SetBounds(100, 100, 220, 150);
DeluxeFormAbout.Caption := 'My dynamic created form';
DeluxeFormAbout.Parent := form_parent;
DeluxeFormAboutCloseButton := TButton.Create(DeluxeFormAbout);
DeluxeFormAboutCloseButton.Caption := 'Close my form';
DeluxeFormAboutCloseButton.SetBounds(10, 10, 200, 30);
DeluxeFormAboutCloseButton.Parent := DeluxeFormAbout;
DeluxeFormAboutCloseButton.OnClick := @DeluxeFormAboutCloseButtonClick;
DeluxeFormAbout.ShowModal;
FreeAndNil(DeluxeFormAbout);
end;
procedure DeluxeFormAboutCloseButtonClick(Sender: TObject);
begin
ShowMessage('Attention, closing my dynamically created form!');
if Sender is TButton then
TForm(TButton(Sender).Parent).Close;
end;
end.
But when I build this unit, I get this error:
unitformdeluxeabout.pas(33,43) Error: Incompatible types: got "<address of procedure(TObject);Register>" expected "<procedure variable type of procedure(TObject) of object;Register>"Is there a simple way to solve this problem?
Thanks so much for any help