請問 array 的一個怪問題 |
答題得分者是:william
|
tony115722
一般會員 發表:53 回覆:63 積分:23 註冊:2002-07-09 發送簡訊給我 |
小弟在使用以下方法時,發現很奇怪的事情耶...
const
def_FieldName: array[1..19] of String = ('CUS_NO','CO_NM','CUS_NM','DR_NM','DL_CD','OUT_DL',
'MOD_CD','CH_NO','EN_NO','CAR_NO','S_ADR_CD','S_ADR2','HO_TEL','CO_TEL','M_PHONE','LA_SA',
'ASK_CD','CUS_ID','IV_NO'); var j:integer;
check:Boolean;
begin
for j := 1 to 19 do begin
if def_FieldName[j]=Name then begin --> j 的值居然是從19,18,17..1
check :=true;
break;
end
else
check :=false;
end;
result:=check; end; 不解...不是應該從 1,2,3..19 嗎? 初學者出沒注意!!
------
I like DeBug |
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
tony115722
一般會員 發表:53 回覆:63 積分:23 註冊:2002-07-09 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
Look at the following code:
procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin for i := 1 to 10 do begin Application.ProcessMessages; end; end;(1) snapshot from CPU window with optimization: (2) snapshot from CPU window without optimization: In 1, there are only dec, jnz compared to inc, cmp, jnz in 2. It is pretty clear that 1 is more efficient. Hence the compiler is smart enough in choosing form 1 for you. In you case, the compiler also knows about the constant array def_FieldName and j is used only as an index of it, thus it performs proper mappings and your checking should goes from 'CUS_NO' to 'IV_NO'. |
tony115722
一般會員 發表:53 回覆:63 積分:23 註冊:2002-07-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |