用 ActionList: procedure TForm1.Button1Click(Sender: TObject); begin if Button2 = nil then begin Button2 := TButton.Create(FORM1); Button2.Parent := FORM1; Button2.Caption := 'Button2'; Button2.OnClick := ActionList1.Actions[0].OnExecute; end else showmessage('already exist'); end;procedure TForm1.BitBtn1Click(Sender: TObject); begin if Button2 <> nil then begin Button2.Free; Button2 := nil; end;end;procedure TForm1.Action1Execute(Sender: TObject); begin showmessage('button2'); end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button2 = nil then
begin
Button2 := TButton.Create(FORM1);
Button2.Parent := FORM1;
Button2.Caption := 'Button2';
Button2.OnClick := ActionList1.Actions[0].OnExecute;
end
else
showmessage('already exist');
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if Button2 <> nil then
begin
Button2.Free;
Button2 := nil;
end;end;procedure TForm1.Action1Execute(Sender: TObject);
begin
showmessage('button2');
end;
procedure MyKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);试试