用FindComponent()函数应该可以.procedure TForm1.TabSheet1Show(Sender: TObject); var MyButton: TButton; begin if TButton(FindComponent('MyButton1')).Caption<> 'MyButton' then begin MyButton:= TButton.Create(self); MyButton.Parent:= TabSheet1; MyButton.Name:= 'MyButton1'; MyButton.Caption:= 'MyButton'; end; end; 不知道你是不是想要这样的效果?
showmessage('The Button already created');
用Tag来判断:
begin
if PageControl1.ActivePage.Tag = 1 then Exit;
PageControl1.ActivePage.Tag := 1;
...
创建组件
...
end;
if groupbox1.ContainsControl(button1)=true then "已经创建"
var
MyButton: TButton;
begin
if TButton(FindComponent('MyButton1')).Caption<> 'MyButton' then
begin
MyButton:= TButton.Create(self);
MyButton.Parent:= TabSheet1;
MyButton.Name:= 'MyButton1';
MyButton.Caption:= 'MyButton';
end;
end;
不知道你是不是想要这样的效果?