如何找出所有有某屬性的元件

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

如何找出所有有某屬性的元件

文章 tim »

如: 找出 form 上所有含有 imename 屬性的元件:
記得要 uses typinfo;

代碼: 選擇全部

     
    procedure Tform1.Button1Click(Sender: TObject); 
    var 
      PropInfo: PPropInfo; 
      i: integer; 
    begin 
      for i := 0 to ComponentCount-1 do 
      begin 
        PropInfo := GetPropInfo(Components[i].ClassInfo,'imename'); 
        if PropInfo <> nil then 
          showmessage(Components[i].Name); 
      end; 
    end; 
若要進行修改該屬性, 可以利用:

SetOrdProp
SetEnumProp
SetSetProp
SetObjectProp
SetStrProp
SetWideStrProp
SetFloatProp
SetVariantProp
SetMethodProp
SetInt64Prop
SetInterfaceProp
SetPropvalue

將 Set 改為 Get 即為取得該屬性

代碼: 選擇全部

    procedure Tform1.Button1Click(Sender: TObject); 
    var 
      PropInfo: PPropInfo; 
      i: integer; 
    begin 
      for i := 0 to ComponentCount-1 do 
      begin 
        PropInfo := GetPropInfo(Components[i].ClassInfo,'imename'); 
        if PropInfo <> nil then 
    //      showmessage(Components[i].Name); 
          SetStrProp(Components[i], PropInfo, '中文 (繁體) - 注音'); 
      end; 
    end; 
多多留言, 整理文章, 把經驗累積下來.....
回覆文章