小弟在FORM中有若干个组件,类型有十几种,如TEdit,TButton等等,请问判断了各组件是否有Caption属性后,怎样把有Caption属性的组件的Caption改成Ini文件内相应的值(Ini文件内的键名和组件的NAME是一致的).
问题关键是:因为我用FORM的TComponent遍历所有组件,所以在赋值时要改类型(如:TLabel(Component).Caption),但我用的组件类型太多,总不能用十多个else if来套类型吧,请问有无一些好一点的方法呢?来万望各位大哥帮忙。
问题关键是:因为我用FORM的TComponent遍历所有组件,所以在赋值时要改类型(如:TLabel(Component).Caption),但我用的组件类型太多,总不能用十多个else if来套类型吧,请问有无一些好一点的方法呢?来万望各位大哥帮忙。
2)用 (AComponent as TControl).Caption
if IsPublishedProp(Edit1,Caption) then//IsPublishedProp(TEdit,'text')也可以
begin
Caption:='存在'
(AComponent as TControl).Caption
end;
else
Caption:='不存在'
然后
if IsPublishedProp(Edit1,'text') then//IsPublishedProp(TEdit,'text')也可以
begin
if Components[LoopCount] is TDBCheckBox then
(Components[LoopCount] as TDBCheckBox).Caption:='-----';
end;