線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1291
推到 Plurk!
推到 Facebook!

未知元件之property

尚未結案
FreeAsABird
一般會員


發表:1
回覆:2
積分:0
註冊:2005-03-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-24 20:11:40 IP:219.132.xxx.xxx 未訂閱
求教大大: 如下code procedure SetCompText(Component: TComponent); begin if GetPropInfo(Component.ClassInfo, 'text') <> nil then Component.text := 'text'; end; Compile Error: Undeclared identifier: text 因元件可能是TEdit,TComboBox ...,不能用如TEdit(Component).text,有預編譯指令可禁止檢查或有其他做法么?
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-24 20:36:55 IP:211.22.xxx.xxx 未訂閱
 if Componet is TEdit then
 begin
  ( Component as TEdit).text := 'text';
  .....
 end
 else if Component is TComboBox then
  ....
 else if Component is TMemo then
  ....
 else
  ....
---------------------------------------------- We will either find a way, or make one. -Hannibal -。
FreeAsABird
一般會員


發表:1
回覆:2
積分:0
註冊:2005-03-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-24 20:44:24 IP:219.132.xxx.xxx 未訂閱
有預編譯指令可禁止檢查么? 我的作法跟大大差不多,但由于元件太多看有否其它好的作法?
speedup
資深會員


發表:19
回覆:259
積分:280
註冊:2003-07-04

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-08-25 18:10:55 IP:220.139.xxx.xxx 未訂閱
引言: 求教大大: 如下code procedure SetCompText(Component: TComponent); begin if GetPropInfo(Component.ClassInfo, 'text') <> nil then Component.text := 'text'; end; Compile Error: Undeclared identifier: text
修改如下,你可以直接參考typinfo單元 裡面有一堆控制RTTI屬性的方法
var propInfo:PPropInfo;
begin
 propInfo := GetPropInfo(Component,'Text');
 if propInfo <>  nil then
 begin
  SetStrProp(Comp,propInfo,'Text');
 end;
end;     
混心雜欲 棄修身~唉
------
唉~
FreeAsABird
一般會員


發表:1
回覆:2
積分:0
註冊:2005-03-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-08-25 18:48:40 IP:219.132.xxx.xxx 未訂閱
看了下SOURCE CODE, thank to Stallion and speedup
系統時間:2024-04-20 18:45:27
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!