MDIForm onDestroy 事件.. |
答題得分者是:ccchen
|
littlefactor
一般會員 發表:24 回覆:25 積分:9 註冊:2002-07-11 發送簡訊給我 |
各位前輩您們好~
小妹我在寫程式時遇到一些問題 情況如下:
1.我在寫類似database desktop的程式,使用MDI方法,有參考JEDI Database Desktop和Dbutil32這兩支程式
2.有兩個procedure :menu_false->控制沒有MDIForm 時選單的狀況,
menu_check->控制每個form on activate時選單的狀況
3.Browser為所有MDIForm的中心,一但關閉,其他MDIForm都一起關掉,並控制選單 4.為了做到3.,我使用下列做法 procedure TCFmBrowser.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end; procedure TCFmBrowser.FormDestroy(Sender: TObject);
var
iCount : integer;
begin for iCount := 0 to MainForm.MDIChildCount - 1 do
begin
MainForm.MDIChildren[iCount].Close;
end;
close_flag := True;
// true 為 form close 的訊息 ,使各個MDIForm 在close時,不去呼叫menu_check
MainForm.menu_false; end; 如此便能做到.. 我有試過很多做法例如
把以下這段寫成procedure 來呼叫=>不支援,或是直接寫在OnClose事件中->不支援,不然就是不跑那段,一直卡在前面,造成程式類似無窮迴圈
都是卡在這裡,只好用到OnDestroy..
for iCount := 0 to MainForm.MDIChildCount - 1 do
begin
MainForm.MDIChildren[iCount].Close;
end; 5.我想File->Select Alias 中點選的話,一樣所有的MDIform都關掉,然後再creat一次select alias form 讓user點選..結果3.做到的前提,
第一次create Select Alias form沒問題,
第二次在create時Select Alias form 有create出來
但在關掉MDIForm時,會呼叫到procedure TCFmBrowser.FormDestroy 結果被關掉了..T_T
大家試一下便知道了 我還有想到最後一招,就是要讓user全部關掉MDIForm,才能讓他點選選單上 Select Alias,
是可以解決問題啦,可是總覺得很笨..一定有其他解決方法 我說明這樣會不會太複雜?!
程式已上傳
請大家能給我點解決問題idea,
我試過好幾種方法,但無法解決,謝謝您們~
| ||
ccchen
版主 發表:61 回覆:940 積分:1394 註冊:2002-04-15 發送簡訊給我 |
1.加一行 application.ProcessMessages就可以了
procedure TMainForm.MU_SelectaliasClick(Sender: TObject); var iCount: Integer; begin if MDIChildCount > 0 then begin for iCount := 0 to MDIChildCount - 1 do MDIChildren[iCount].Close; //由於TCFmBrowser之close 停在messageQueue中,故當下行formcreate後再去執行close, 由TCFmBrowser之onDestroy把剛create之form也close了 application.ProcessMessages; //加此行使messagequeue中之所有close先完成再執行create就可以了 CFmSelect_Alias := TCFmSelect_Alias.Create(application); ... end2. 或是直接寫在OnClose事件中->不支援 那是當然, close所有MDIChild當然包含本身, 應此再之觸動了onClose造成無窮迴圈 3.把以下這段寫成procedure 來呼叫=>不支援 不知何意, 寫成procedure 來呼叫應該可以, 我試了一下 a. 在main.pas中最前 ... procedure closemdichild; implementation uses Data_Module, Select_Alias, SQL_Query, Browser, Table_Data, Customize_Columns; {$R *.dfm} procedure closemdichild; var icount:integer; begin for iCount := 0 to MainForm.MDIChildCount - 1 do begin MainForm.MDIChildren[iCount].Close; end; end;b. 在main.pas之MU_SelectaliasClick if MDIChildCount > 0 then begin closemdichild; // for iCount := 0 to MDIChildCount - 1 do // MDIChildren[iCount].Close; //or 直接使用 CFmBrowser.FormDestroy(Sender); application.ProcessMessages; CFmSelect_Alias := TCFmSelect_Alias.Create(application); ...c. procedure TCFmBrowser.FormDestroy(Sender: TObject); var iCount : integer; begin closemdichild; close_flag := True; MainForm.menu_false; end;發表人 - ccchen 於 2002/08/29 20:46:14 |
||
jieshu
版主 發表:42 回覆:894 積分:745 註冊:2002-04-15 發送簡訊給我 |
引言:for iCount := 0 to MainForm.MDIChildCount - 1 do begin MainForm.MDIChildren[iCount].Close; end; for iCount := MainForm.MDIChildCount - 1 downto 0 do MainForm.MDIChildren[iCount].Close;關閉視窗或是釋放元件時,最好由大到小。
------
人生有夢,逐夢而行 人若為善,福雖未至,禍已遠離 人若為惡,禍雖未至,福已遠離 http://www.taconet.com.tw/jieshu/ |
||
littlefactor
一般會員 發表:24 回覆:25 積分:9 註冊:2002-07-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |