在组件设计中:
第一步:
type
TMyClickEvent = procedure(Sender: TObject; myId: Integer) of object;
第二步:
private
FOnMyClick :TMyClickEvent;
procedure MyClick(Sender: TObject);
第三步:
published
property OnMyClick :TMyClickEvent read FOnMyClick write FOnMyClick;
第四步:
procedure TForm1.MyClick(Sender: TObject);//把TForm1改为你组件类名
var
myId :integer;
begin
myId := 0;
if (Sender is TPanel) then myId:=1;
if (Sender is TLabel) then myId:=2;
if (Sender is TSpinEdit) then myId:=3;
if Assigned(FOnMyClick) then FOnMyClick(Self, myId);
end;
第五步:
在组件中构建你的TPanel、TLabel、TSpinEdit等时,将它们的Click事件设置为MyClick.
例:Panel1.OnClick:= MyClick;
还有不明白的吗?