将一个字符串映射为一个Delphi页面控件属性名(通过FindComponent和GetPropInfo找到这个控件指针)


uses   TypInfo;   
    
  function   TForm1.SetControlProp(ComStr,   value:   string):   boolean;   
  var   ComName,   ComProp:   string;   
          i:   integer;   
      Loop:   Integer;   
      PropInfo:   PPropInfo;   
      cp:   TComponent;   
  begin   
      i   :=   Pos('.',   ComStr);   
      if   i   >   0   then   
      begin   
          ComName   :=   copy(ComStr,   1,   i-1);   
          ComProp   :=   Copy(Comstr,   i+1,   1000);   
          cp   :=   FindComponent(ComName);   
          PropInfo   :=   GetPropInfo(cp.ClassInfo,   ComProp);   
          if   Assigned(PropInfo)   then   
              SetStrProp(cp,   PropInfo,   value);   
      end;   
  end;   
    
  procedure   TForm1.Button3Click(Sender:   TObject);   
  begin   
    SetControlProp('button1.caption',   'test');   // 設置button1的caption   為   test   
  end;   

 

http://www.cnblogs.com/kfarvid/archive/2009/10/19/1586229.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM