將一個字符串映射為一個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