Form1调用Unit2类中函数
Form1有一个button,当Form1.Create时触发Button的OnClick事件,OnClick事件调用Unit2单元中的函数;
unit Unit2; interface uses FMX.Dialogs, FMX.StdCtrls; type TBClick = class private public procedure BClick(Sender: TObject); end; implementation { BClick } procedure TBClick.BClick(Sender: TObject); begin ShowMessage('hello'); end; end.
unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls; type TForm2 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation uses Unit3; {$R *.fmx} { TForm2 } procedure TForm2.FormCreate(Sender: TObject); var bclick: TBClick; begin Button1.OnClick := bclick.BClick; Button1.OnClick(Sender); // hello end; end.