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

為什麼沒有設定tcombobox的值, 也會出現數值

答題得分者是:william
poemkevin
初階會員


發表:26
回覆:77
積分:30
註冊:2002-10-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-14 09:17:35 IP:210.202.xxx.xxx 未訂閱
這是在大陸網站上看到有人發問的問題, 都沒人解答. 蠻奇怪的問題, 視窗只有放一個Button1元件, procedure TForm1.Button1Click(Sender: TObject); var xx:TComboBox; begin showmessage(xx.text); //xx是TComboBox不是TButton,而且未初始化 end; 它顯示出來的值, 居然是Button1.Caption的值 procedure TForm1.Button1Click(Sender: TObject); var xx:TComboBox; begin showmessage(xx.Name); //xx是TComboBox不是TEdit,而且未初始化 end; 它顯示出來的值, 居然是Form1.Name的值 覺得蠻奇怪的, 為什麼沒有設定tcombobox的值, 也會出現數值=.= =========================== 沉思, 再沉思! 學習, 再學習! 生活隨喜, 簡單自在^^ ===========================
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-14 10:37:41 IP:147.8.xxx.xxx 未訂閱
Optimization on? It is a bug... but I would rather blame the one who write this kind of code, not the compiler... warning should had been issued already...    The compiler somehow decide that xx is not used in the whole procedure, so xx is removed from the local stack...    Try below procedure with Optimization on. AV when the // test line is commented out (i.e. i will NOT be removed from the local stack due to optimization since it is in use now).  
procedure TForm1.Button1Click(Sender: TObject);
var
    i: integer;
    xx: TComboBox;
begin
    showmessage(xx.Text);
    showmessage(IntToStr(i)); // test
end;
poemkevin
初階會員


發表:26
回覆:77
積分:30
註冊:2002-10-19

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-09-14 11:43:01 IP:210.202.xxx.xxx 未訂閱
引言: Optimization on? It is a bug... but I would rather blame the one who write this kind of code, not the compiler... warning should had been issued already... The compiler somehow decide that xx is not used in the whole procedure, so xx is removed from the local stack... Try below procedure with Optimization on. AV when the // test line is commented out (i.e. i will NOT be removed from the local stack due to optimization since it is in use now).
procedure TForm1.Button1Click(Sender: TObject);
var
    i: integer;
    xx: TComboBox;
begin
    showmessage(xx.Text);
    showmessage(IntToStr(i)); // test
end;
謝謝大大的回應. 很感謝^^ 小弟以前曾寫程式時, 忘了給整數變數初始值, 就會亂跳一下數字出來 那時就覺得有點納悶,為什麼delphi 上會允許這些bug存在? =========================== 沉思, 再沉思! 學習, 再學習! 生活隨喜, 簡單自在^^ ===========================
系統時間:2024-05-18 12:42:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!