随便建立一个包(package).然后建立一个单元文件.把下面的代码拷贝进去.安装这个包.
在组建面板上的Standard页就增加了这个控件.
拖一个放在界面.
在你的代码里写上
组件.EventForm := XXXFrom;
指定要接受的Form.
当XXXForm上的按钮被点击的时候Event1ClickEvent事件就会被触发.
事件的参数CanDo是是否可以继续执行原来的点击事件.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Unit2, Unit3;
type
TForm1 = class(TForm)
Button1: TButton;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
ButtonEvent1: TButtonEvent;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ButtonEvent1ClickEvent(Sender: TObject; ABtn: TButtonControl;
var CanDo: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('');
end;
procedure TForm1.ButtonEvent1ClickEvent(Sender: TObject; ABtn: TButtonControl;
var CanDo: Boolean);
begin
if TButton(ABtn).Caption <>'aaa' then
CanDo := False;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
//
//Form3.Show;
ButtonEvent1.EventForm := Form1;
end;
end.