小弟在FORM中有若干个组件,类型有十几种,如TEdit,TButton等等,请问判断了各组件是否有Caption属性后,怎样把有Caption属性的组件的Caption改成Ini文件内相应的值(Ini文件内的键名和组件的NAME是一致的).
问题关键是:因为我用FORM的TComponent遍历所有组件,所以在赋值时要改类型(如:TLabel(Component).Caption),但我用的组件类型太多,总不能用十多个else if来套类型吧,请问有无一些好一点的方法呢?来万望各位大哥帮忙。

解决方案 »

  1.   

    1)尽可能在ini中定义类型
    2)用 (AComponent as TControl).Caption
      

  2.   

    (AComponent as TControl).Caption
      

  3.   

    (AComponent as TControl).Caption
      

  4.   

    (AComponent as TControl).Caption
      

  5.   

    (AComponent as TControl).Caption
      

  6.   

    不行啊!编译器说:TControl的Caption不可识别,为什么会这样的呢?
      

  7.   

    判断Edit1,是否有text属性 
    if IsPublishedProp(Edit1,Caption) then//IsPublishedProp(TEdit,'text')也可以 
    begin
        Caption:='存在'
    (AComponent as TControl).Caption
    end;
      else
        Caption:='不存在'
    然后
      

  8.   

    失误,应该是
    if IsPublishedProp(Edit1,'text') then//IsPublishedProp(TEdit,'text')也可以
      

  9.   

    [Error] UniDtChg.pas(94): Undeclared identifier: 'Caption'
      

  10.   

    For LoopCount:=0 to ComponentCount-1 do
      begin
        if Components[LoopCount] is TDBCheckBox then
          (Components[LoopCount] as TDBCheckBox).Caption:='-----';
      end;