全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2462
推到 Plurk!
推到 Facebook!

Delphi中遍历窗体中所有组件的Caption及Hint,并添加到ini文件中

答題得分者是:wameng
piaolingfeihu
一般會員


發表:7
回覆:12
積分:3
註冊:2007-06-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-07-24 18:29:16 IP:61.183.xxx.xxx 訂閱
Delphi中遍历窗体中所有组件的Caption及Hint,并添加到ini文件中。各位大哥,请不吝赐教,小弟不胜感激!]
我写一个递归函数,可以遍历所有组件但是我不知道该怎么样获取组件可显示内容的信息,比如: Caption,Hint,Text等属性,我的目的是将这些属性写到ini文件中。函数如下:

procedure FindAllComponents(Form: TForm; ParentComponent: TComponent; IniFile: TIniFile; defaultText: string);
var
iCount, iIndex: Integer;
begin
if not Assigned(Form) then Exit;
if not Assigned(ParentComponent) then Exit;
if not Assigned(IniFile) then Exit;

iCount := ParentComponent.ComponentCount - 1;
with ParentComponent do begin

for iIndex := 0 to iCount do begin
if (Components[iIndex].Name = '') then Continue;
ReplaceComponents(Form, IniFile, Components[iIndex], defaultText); //为读文件可显示内容的函数,为读ini文件所用

if ComponentCount > 0 then begin
FindAllComponents(Form, Components[iIndex], IniFile, defaultText); //递归算法
end;
end;
end;
end;



procedure ReplaceComponents(Form: TForm; IniFile: TIniFile; frmComponent: TComponent; const defaultText: string);
var
Section: string;
temp, i, j, idx, y: Integer;
begin
if not Assigned(Form) then Exit;
if not Assigned(IniFile) then Exit;
Section := Form.Name;
with IniFile do begin
//01 TRzBmpButton类处理Caption和 Hint属性
if (frmComponent is TRzBmpButton) then begin
with frmComponent as TRzBmpButton do begin
if Caption <> '' then
Caption := ReadString(Section, name '.Caption', defaultText);
if Hint <> '' then
Hint := ReadString(Section, name '.Hint', defaultText);
end;
Exit;
end;
现在就是想把通过遍历得出信息并写到ini文件中,如:

Button.Caption=确定
Label.text=文本…………


希望各位大大不吝赐教!小弟感激不尽!
谢谢您的浏览!

------
没有做不到,只有想不到!
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-07-24 18:36:21 IP:61.222.xxx.xxx 訂閱
利用 TypInfo

function GetStrProp(Instance: TObject; const PropName: string): string;
取得字串屬性內容。
系統時間:2024-05-07 14:58:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!