unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) mmo1: TMemo; scrlbx1: TScrollBox; btn1: TButton; btn2: TButton; edt1: TEdit; procedure FormCreate(Sender: TObject); procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var i:Integer; edtTmp :TEdit; begin for i:=0 to 5 do begin edtTmp := TEdit.Create(scrlbx1); edtTmp.Parent := scrlbx1; edtTmp.Text := 'edtText'+ IntToStr(i); edtTmp.Name := 'edtName'+ IntToStr(i); edtTmp.Left := 5; edtTmp.Top := edtTmp.Height*i + 5; end; end; procedure TForm1.btn1Click(Sender: TObject); var i: Integer; begin //ComponentCount 表示该组件拥有的子组件数据 //Components 可以访问该组件拥有的任何子组件 mmo1.Lines.Add('控件scrlbx1拥有组件数为:'+inttostr(scrlbx1.ComponentCount)+' 组件名分别为:'); for i:= 0 to scrlbx1.ComponentCount -1 do begin mmo1.Lines.Add(scrlbx1.Components[i].Name); // 这里不会显示edt1的name 因为它不属于scrlbx1 end; end; procedure TForm1.btn2Click(Sender: TObject); var i: Integer; begin mmo1.Lines.Add('控件scrlbx1所有组件数为:'+inttostr(scrlbx1.ControlCount)); //ControlCount 表示该组件所有(不是拥有,放在该组件上面的都算所有)的子组件数据 for i:= 0 to scrlbx1.ControlCount - 1 do begin if scrlbx1.Controls[i] is TEdit then begin TEdit(scrlbx1.Controls[i]).Clear; //这里会清除edt1 里的内容 end; end; end; end.