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

請問動態產生視窗

缺席
jazz
初階會員


發表:10
回覆:43
積分:35
註冊:2002-06-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-11-05 20:46:52 IP:61.30.xxx.xxx 未訂閱
我一個MainForm動態產生Form2 TForm2 *Form2; try{ Form2 = new TForm2(Application); Form2->Parent = Form2; Form2->ShowModal(); delete Form2; } catch(Exception &exception){ delete Form2; Application->ShowException(&exception); } 再由Form2上的一個Button再動態產生Form3 程式碼一樣如上 可是每當我Form3的程式跟Form2的元件扯上關係時都會有錯誤 例如判斷Form2->RadioGroup->ItemIndex==0 遇到這一行就錯誤 我Form3已經有include Form2.h了 奇怪 為什麼會這樣呢? 敢請各位先進為我解答
lcsboy
版主


發表:87
回覆:622
積分:394
註冊:2002-06-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-11-07 00:35:35 IP:210.85.xxx.xxx 未訂閱
把code po上來吧! 說不定是你的parent沒設或設錯了
jazz
初階會員


發表:10
回覆:43
積分:35
註冊:2002-06-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-11-07 09:06:17 IP:61.16.xxx.xxx 未訂閱
版主大大 我已經捉到原因了,從BCB6的英文手冊看到的 An event handler for the main form must create an instance of the result form and destroy it. One way to invoke the result form is to use the global variable as follows. Note that ResultsForm is a modal form so the handler uses the ShowModal method. void __fastcall TMainMForm::FirstButtonClick(TObject *Sender) { ResultsForm = new TResultsForm(this); ResultsForm->ShowModal(); delete ResultsForm; } Creating a form instance using a local variable A safer way to create a unique instance of a modal form is to use a local variable in the event handler as a reference to a new instance. If a local variable is used, it does not matter whether ResultsForm is auto-created or not. The code in the event handler makes no reference to the global form variable. For example: void __fastcall TMainMForm::FirstButtonClick(TObject *Sender) { TResultsForm *rf = new TResultsForm(this);// rf is local form instance rf->ShowModal(); delete rf; // form safely destroyed }
系統時間:2024-04-19 11:52:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!