怎样在程序中遍历某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[i] is TLabel then
listbox1.Items.Add((Components[i] as TLabel).Caption);
if Components[i] is Tbutton then
listbox1.Items.Add((Components[i] as Tbutton).Caption);
end;
end;
这段代码是分开一种一种的控件来添加,能否一次性添加,不用分哪种控件?
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ComponentCount - 1 do
begin
if Components[i] is TLabel then
listbox1.Items.Add((Components[i] as TLabel).Caption);
if Components[i] is Tbutton then
listbox1.Items.Add((Components[i] as Tbutton).Caption);
end;
end;
这段代码是分开一种一种的控件来添加,能否一次性添加,不用分哪种控件?
解决方案 »
- 怎么在rave中打印条码?如何传递条码的值?
- 如何讲OBJ文件link后的exe文件转换成Hex或Bin文件,或OBJ直接Link成Hex文件
- 如何控制计算得到的数值的格式?
- qreport的设计中我分组显示了查询的结果,并且想count每组的记录数量,怎么做啊?
- 接:遇到一个问题: 象$D7、$08是不是代表十六进制? 如何计算一个表达式? 高分求教
- 有关于CRYSTAL REPORTS的几个菜鸟问题!!
- ***如何实现从某一基数实现编号的自动生成****
- 在一个FORM中有二个DBGRID一个是显示的是表中工作单位dbgrid1一个是显示人员信息dbgrid2(同一个表)怎么样才可以使点dbgrid中的一个工作单
- delphi和C++ Builder
- 求助:怎样编写局域网管理软件
- 怎样在线程中创建 TIdTCPClient 对象进行连接
- richedit如何实现文字链接
其它控件继承TControl,需要的时候才将它发布。用GetWindowText试试
uses TypInfo;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
propinfo: PPropInfo;
var
i: Integer;
begin
for i := 0 to ComponentCount - 1 do
begin
PropInfo := GetPropInfo(Components[i].ClassInfo, 'Caption');
if propinfo <> nil then
listbox1.Items.Add(GetStrProp(Components[i], 'Caption'));
end;
end;
TMyControl = class(TControl)
end;procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to ControlCount - 1 do
listbox1.Items.Add(TMyControl(Controls[i]).Caption);
end;