var ii:integer; begin for ii:=0 to ComponentCount -1 do if Components [ii] is TLabel then (Components [ii] as TLabel).Caption:='test'; end; 插入条件'Test'设为活动的变量就OK,根据条件改吧结贴吧
规律当然有! 只少label是从1-20,其它的可以先不管。 我们用的最多的方法是一个个的写。可这样不灵活。 Label1.caption:='test' .....2.caption:='test' .................... 有没有这样的办法: for i:=1 to 20 do lable[i].caption:='test'; 不过写出来报错.
同意: wofan(我烦) ,给分吧!
use Inifiles;// 从Ini文件中读 var frmComponent : TComponent; i : Integer; str : String; begin // read ini file to initialization interface component with TInifile.Create(FilePath + 'Test.ini') do begin for i := 0 to ComponentCount-1 do begin frmComponent := Components[i]; if frmComponent is TLabel then begin (frmComponent as TLabel).Caption := ReadString(RSection,frmComponent.Name + '.Caption',(frmComponent as TLabel).Caption); end; end; end; end;
你可以理解为Form上控件的数目
看不懂!这和ini文件有什么关系呀!
没这么复杂吧?!vb很简单的呀! vb: for i=1 to 5 label1(i).caption="a" next 这就可以了!
如: Label1.caption='test'
.....2.caption='test'
....................
在比如有很多dbedit,根据选择的表的不同,所以它们的数据源需要动态的改变。
ii:integer;
begin
for ii:=0 to ComponentCount -1 do
if Components [ii] is TLabel then
(Components [ii] as TLabel).Caption:='test';
end;
插入条件'Test'设为活动的变量就OK,根据条件改吧结贴吧
只少label是从1-20,其它的可以先不管。
我们用的最多的方法是一个个的写。可这样不灵活。
Label1.caption:='test'
.....2.caption:='test'
....................
有没有这样的办法:
for i:=1 to 20 do
lable[i].caption:='test';
不过写出来报错.
var
frmComponent : TComponent;
i : Integer;
str : String;
begin
// read ini file to initialization interface component
with TInifile.Create(FilePath + 'Test.ini') do
begin
for i := 0 to ComponentCount-1 do
begin
frmComponent := Components[i];
if frmComponent is TLabel then
begin
(frmComponent as TLabel).Caption :=
ReadString(RSection,frmComponent.Name + '.Caption',(frmComponent as TLabel).Caption);
end;
end;
end;
end;
vb:
for i=1 to 5
label1(i).caption="a"
next
这就可以了!
我在问一下,这种办法适用于其它控件吗?如:dbedit,edit,editmast......