請問一下元件若宣告好命名, 是否可以以在元件後加上動態數字來呼叫 |
答題得分者是:hagar
|
poemkevin
初階會員 發表:26 回覆:77 積分:30 註冊:2002-10-19 發送簡訊給我 |
宣告
edit1_1:TEdit;
edit1_2:Tedit;
edit2_1:TEdit;
edit2_2:TEdit;
edit3_1:TEdit;
edit3_2:TEdit; 程式 for i=1 to 3 do
begin
edit[inttostr(i) '_1].Text:='ss';
edit[inttostr(i) '_2].Text:='bb';
end; 請問一下元件若宣告好命名, 是否可以以在元件後加上動態數字來呼叫 這樣的寫法edit[inttostr(i) '_1].Text
執行的時候, 它會出現 edit沒有被宣告定義,
請問各位前輩, 在前面宣告不變, 是否有解決的方法!!
謝謝! 沉思, 再沉思! 學習, 再學習!
生活隨喜, 簡單自在^^
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
利用 FindComponent 來做
var edt: TEdit; begin for i := 1 to 3 do begin edt := Form1.FindComponent('edit' IntToStr(i) '_1') as TEdit; if edt <> nil then edt.Text := 'ss'; edt := Form1.FindComponent('edit' IntToStr(i) '_2') as TEdit; if edt <> nil then edt.Text := 'bb'; end;-- 歡迎光臨 KTop 研究院! 發表人 - hagar 於 2004/08/23 15:14:19 |
poemkevin
初階會員 發表:26 回覆:77 積分:30 註冊:2002-10-19 發送簡訊給我 |
引言: 利用 FindComponent 來做謝謝hagar大大的解答,感激不盡^^ 小弟之前也有試過 FindComponent 這方法, 不過我的用法錯誤, 難怪試不出來 我之前是這樣寫的 for i=1 to 3 do begin Form1.FindComponent('edit' IntToStr(i) '_1').text:='ss'; Form1.FindComponent('edit' IntToStr(i) '_2').text:='bb'; end; 所以程式怎麼run都會出錯 不知除了這方法外,是否還有其他的寫法? 沉思, 再沉思! 學習, 再學習! 生活隨喜, 簡單自在^^var edt: TEdit; begin for i := 1 to 3 do begin edt := Form1.FindComponent('edit' IntToStr(i) '_1') as TEdit; if edt <> nil then edt.Text := 'ss'; edt := Form1.FindComponent('edit' IntToStr(i) '_2') as TEdit; if edt <> nil then edt.Text := 'bb'; end;-- 歡迎光臨 KTop 研究院! 發表人 - hagar 於 2004/08/23 15:14:19 |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
您的寫法可以改成如下:
for i := 1 to 3 do begin TEdit(Form1.FindComponent('edit' IntToStr(i) '_1')).Text := 'ss'; TEdit(Form1.FindComponent('edit' IntToStr(i) '_2')).Text := 'bb'; // 或是 (Form1.FindComponent('edit' IntToStr(i) '_1') as TEdit).Text := 'ss'; (Form1.FindComponent('edit' IntToStr(i) '_2') as TEdit).Text := 'bb'; end;-- 歡迎光臨 KTop 研究院! |
poemkevin
初階會員 發表:26 回覆:77 積分:30 註冊:2002-10-19 發送簡訊給我 |
引言: 您的寫法可以改成如下:hagar大大, 這真是太棒了, 原來寫程式這麼有趣, 同一種結果, 可以有不同方法去解決. 真的很感謝您的指導^^for i := 1 to 3 do begin TEdit(Form1.FindComponent('edit' IntToStr(i) '_1')).Text := 'ss'; TEdit(Form1.FindComponent('edit' IntToStr(i) '_2')).Text := 'bb'; // 或是 (Form1.FindComponent('edit' IntToStr(i) '_1') as TEdit).Text := 'ss'; (Form1.FindComponent('edit' IntToStr(i) '_2') as TEdit).Text := 'bb'; end;-- 歡迎光臨 KTop 研究院! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |