[阅读: 864] 2009-03-27 13:36:19
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;