請教有關 event trigger的問題 |
尚未結案
|
slam3556
一般會員 發表:1 回覆:2 積分:0 註冊:2005-08-09 發送簡訊給我 |
|
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
可以作到類似 pre-trigger,利用 TApplication::OnMessage 事件,
以下是 BCB 的線上說明:
引言: TApplication::OnMessage Occurs when the application receives a Windows message. Description Use OnMessage to trap any or all Windows messages posted to all windows in the application. The OnMessage event occurs when an application receives a Windows message. An OnMessage event handler allows an application to respond to messages other than those declared in the events for TApplication. If the application doesn't have a specific handler for an incoming message, the message is dispatched to the window for which it was intended, and Windows handles the message. The TMessageEvent type is the type of the OnMessage event. The Msg parameter identifies the Windows message, and the Handled parameter indicates whether the event handler responded to the message. Set Handled to true if the message has been completely handled, to prevent subsequent processing of the message. Note: OnMessage only receives messages that are posted to the message queue, not those sent directly with the Windows API SendMessage function. Caution: Thousands of messages per second flow though this event. Be careful when coding the handler, because it can affect the performance of the entire application. OnMessage Example The following code handles a custom message that the application sends to itself when a file is ready for reading.只要自己瞭解整個 Application 的所有事件即可 > < href="http://free.greenworld.com.tw/~dllee/" target="blank">吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Beckhoff Fieldbusconst WM_FILEREADY = WM_USER 2000; void __fastcall TForm1::FormCreate(TObject *Sender) { Application->OnMessage = AppMessage; } void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled) { if (Msg.message == WM_FILEREADY) { Memo1->Lines->LoadFromFile(AnsiString((char *)Msg.lParam)); Handled = true; } /* for all other messages, Handled remains False so that other message handlers can respond */ }
------
http://www.ViewMove.com |
slam3556
一般會員 發表:1 回覆:2 積分:0 註冊:2005-08-09 發送簡訊給我 |
|
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
真的有必要嗎?我認真的想了想...
大部份的事件也是在程式中去叫用而已,特別是 OnCreate 這種流程式的事件,
即然是在原本的流程,pre/post-trigger 就沒有什麼太大的用處,想要的話,
可以自己把每個事件再轉成三個事件,例如:
void __fastcall XXXX::OnCreate(TObject *Sender) { if(PreOnCreate!=NULL) PreOnCreate(Sender); // pre-trigger if(OrgOnCreate!=NULL) OrgOnCreate(Sender); // 原事件 if(PostOnCreate!=NULL) PostOnCreate(Sender); // post-trigger }這樣與叫用三個函式或寫在一起有何差異?! 個人認為,一般流程式的事件應該是不需要作 pre/post trigger 而資料庫元件之所以提供 pre/post trigger,是因為真正操作資料庫 並不是由您的程式完成,而是由資料庫系統完成,所以在 new/delete/modify 資料前,您可以再次確認資料庫是否真的要修改,在資料更新後,您可以決定 是否更新其他資料顯示。 PowerBuilder 我是沒有用過啦,不過,我想它應該是注重在資料庫的使用, 所以會提供 pre/post trigger 是很正常的,如果沒有提供,那就很難用了, 同樣,在 BCB/Delphi 中的資料庫元件也都有提供 pre/post trigger 的事件 也是這個用意。 至於說視窗操作,如按鈕 Click 事件,應該在 Windows 系統本身就沒有提供 PreClick, PostClick 的事件了吧,當然,也可以使用 MouseDown, MouseUp 事件來代替,但是,就沒有 PreMouseDown, PostMouseDown 的事件可以代替了, 相信,這些事件在 PowerBuidler 中應該也是沒有的吧!! C# 初學者請多指教 < href="http://free.greenworld.com.tw/~dllee/" target="blank">吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Beckhoff Fieldbus VMASK
------
http://www.ViewMove.com |
slam3556
一般會員 發表:1 回覆:2 積分:0 註冊:2005-08-09 發送簡訊給我 |
版大說的沒錯
Powerbuilder就是專門針對資料庫開發用的語言
版大這番解釋,讓我對trigger又多了一層認識
我也認為並不是每個event都一定要有pre/post trigger
但是需要的原因就是希望可以確認某個動作已經完成
而這個動作又不知道該怎樣確認是否完成
所以才會就整個event來看完成與否
回應中所說可將原事件拆成三個來作
可否請版大出示大略的程式碼供小弟參考 此問題至此已有答案
感謝dllee的解答 發表人 - slam3556 於 2005/09/28 10:46:27
|
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
參考這篇
【BCB】【問題】變數事件的產生
http://delphi.ktop.com.tw/topic.php?topic_id=44151
引言:以此為例,多宣告 紅色部分typedef void __fastcall (__closure *TChangeVarEvent)(); class TMyClass { private: int FVar; void __fastcall ChangeVar(); // Trigger Event Function TChangeVarEvent FOnChangeVar; // Event public: __fastcall TMyClass(); void __fastcall AddVal(); __property TChangeVarEvent OnChangeVar = {read = FOnChangeVar,write = FOnChangeVar}; __property int Var = {read = FVar}; }; // TMyClass Constructor __fastcall TMyClass::TMyClass() { FVar = 0; FOnChangeVar = NULL; } //--------------------------------------------------------------------------- void __fastcall TMyClass::AddVal() { FVar ; ChangeVar(); } //--------------------------------------------------------------------------- void __fastcall TMyClass::ChangeVar() { if (FOnChangeVar) FOnChangeVar(); } //--------------------------------------------------------------------------- class TMyClass { private: int FVar; void __fastcall ChangeVar(); // Trigger Event Function TChangeVarEvent FOnChangeVar; // Event TChangeVarEvent FOnPreChangeVar; // Event TChangeVarEvent FOnPostChangeVar; // Event public: __fastcall TMyClass(); void __fastcall AddVal(); __property TChangeVarEvent OnChangeVar = {read = FOnChangeVar,write = FOnChangeVar}; __property TChangeVarEvent OnPreChangeVar = {read = FOnPreChangeVar,write = FOnPreChangeVar}; __property TChangeVarEvent OnPostChangeVar = {read = FOnPostChangeVar,write = FOnPostChangeVar}; __property int Var = {read = FVar}; };在發事件時再加上 void __fastcall TMyClass::ChangeVar() { if (FOnPreChangeVar) FOnPreChangeVar(); if (FOnChangeVar) FOnChangeVar(); if (FOnPostChangeVar) FOnPostChangeVar(); }即可。 C# 初學者請多指教 < href="http://free.greenworld.com.tw/~dllee/" target="blank">吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Beckhoff Fieldbus VMASK
------
http://www.ViewMove.com |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |