對一連串 TEdit 做相同的處理動作 ? |
尚未結案
|
crlin
一般會員 ![]() ![]() 發表:47 回覆:57 積分:20 註冊:2002-07-23 發送簡訊給我 |
我有一連串的 TEdit, 分別是
Edit1, Edit4, Edit7, Edit10, Edit13, ....
若我要對它們做相同的處理動作
如何用 for loop 來達成這個目的呢 ? 例如 for i:=0 to 100 do
begin
'Edit' (1 3i) '.Text' := 'test';
end; 但 compile 時會出現 incomptable types 請問程式碼中 'Edit?' 不能用一個字串來代表嗎 ?
那麼我該如何做呢 ? thanks !
|
cmf
尊榮會員 ![]() ![]() ![]() ![]() ![]() 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
引言: 我有一連串的 TEdit, 分別是 Edit1, Edit4, Edit7, Edit10, Edit13, .... 若我要對它們做相同的處理動作 如何用 for loop 來達成這個目的呢 ? 例如 for i:=0 to 100 do begin 'Edit' +(1 + 3i)+'.Text' := 'test'; end; 但 compile 時會出現 incomptable types 請問程式碼中 'Edit?' 不能用一個字串來代表嗎 ? 那麼我該如何做呢 ? thanks !for i:=0 to ComponentCount-1 do begin if Components[i] is TEdit then begin TEdit(Components[i]).Text:= 'test'; end; end;
------
︿︿ |
crlin
一般會員 ![]() ![]() 發表:47 回覆:57 積分:20 註冊:2002-07-23 發送簡訊給我 |
|
cmf
尊榮會員 ![]() ![]() ![]() ![]() ![]() 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
引言: 但我的程式中並不是只有 Edit1, Edit4, Edit7, Edit10, Edit13 ... 還有 Edit2, Edit3, Edit5, Edit6, ..... 在 Components[i] 中我如何判斷 Edit? 是對應到 Component(i) 的哪一個呢 ? thanks !procedure Tform1.test; var s,s2:string; c:char; i,j:integer; begin for i:=0 to ComponentCount-1 do begin j:=0 if Components[i] is TEdit then begin s:=TEdit(Components[i]).Name; s2:='Edit'+inttostr(1+3*j); if s=s2 then TEdit(Components[i]).Text:= 'test'; inc(j); end; end; end;
------
︿︿ |
ccchen
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:61 回覆:940 積分:1394 註冊:2002-04-15 發送簡訊給我 |
|
crlin
一般會員 ![]() ![]() 發表:47 回覆:57 積分:20 註冊:2002-07-23 發送簡訊給我 |
我照這段程式碼測試的結果
s 的確是我的 Form 上有的 Edit
但 FindComponent(s); 的結果 c 都是 nil
請問為什麼會這樣呢 ?? thanks ! var s:string;
i:integer;
c:TComponent;
begin
for i:=0 to 100 do begin
s:=''Edit'' inttostr(1 3i);
c:=FindComponent(s);
if c <> nil then
TEdit(c).text:=''test'';
end;
end;
|
cmf
尊榮會員 ![]() ![]() ![]() ![]() ![]() 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
引言: 我照這段程式碼測試的結果 s 的確是我的 Form 上有的 Edit 但 FindComponent(s); 的結果 c 都是 nil 請問為什麼會這樣呢 ?? thanks ! var s:string; i:integer; c:TComponent; begin for i:=0 to 100 do begin s:=''Edit''+inttostr(1 + 3i); c:=FindComponent(s); if c <> nil then TEdit(c).text:=''test''; end; end;s:='Edit'+inttostr(1 + 3*i);
------
︿︿ |
mcho
初階會員 ![]() ![]() 發表:57 回覆:106 積分:42 註冊:2002-11-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |