中国开发网: 论坛: 程序员情感CBD: 贴子 708224
pcplayer: 我的写法:
procedure TForm1.Button1Click(Sender: TObject);
var
ALabel: TLabel;
ABtn: TButton;
begin
AForm := TForm.Create(Application);
AForm.Caption := 'aaabbbccc';
AForm.Position := poScreenCenter;


ABtn := TButton.Create(AForm);
ABtn.Parent := AForm;
ABtn.Caption := '哈哈';
ABtn.Left := 20;
ABtn.Top := 20;
ABtn.Name := 'MyButton';
ABtn.OnClick := Self.DoMyBtnClick;

ALabel := TLabel.Create(AForm);
ALabel.Parent := AForm;
ALabel.Caption := '嘿嘿';
ALabel.Name := 'MyLabel';
ALabel.Left := 20;
ALabel.Top := 40;

AForm.Show;
end;

procedure TForm1.DoMyBtnClick(Sender: TObject);
var
i: Integer;
AForm: TWinControl;
begin
AForm := (Sender as TButton).Parent;
for i := 0 to Pred(AForm.ComponentCount) do
begin
if AForm.Components[i] is TLabel then
begin
TLabel(AForm.Components[i]).Caption := 'hello';
end;
end;
end;

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录