R
rgn
Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在程序中遍历某form有caption的控件,并将这些有caption的控件的caption加入到listbox1里面?(这些控件包括有label、button、checkbox等等,不包括edit等)
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components is TLabel then
listbox1.Items.Add((Components as TLabel).Caption);
if Components is Tbutton then
listbox1.Items.Add((Components as Tbutton).Caption);
end;
end;
这段代码是分开一种一种的控件来添加,能否一次性添加,不用分哪种控件?
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components is TLabel then
listbox1.Items.Add((Components as TLabel).Caption);
if Components is Tbutton then
listbox1.Items.Add((Components as Tbutton).Caption);
end;
end;
这段代码是分开一种一种的控件来添加,能否一次性添加,不用分哪种控件?