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

請教有關 event trigger的問題

尚未結案
slam3556
一般會員


發表:1
回覆:2
積分:0
註冊:2005-08-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-09-08 16:05:07 IP:211.76.xxx.xxx 未訂閱
我對BCB是新手,在使用過其他語言像是POWER BUILDER之後, 覺得post-trigger及pre-trigger相當好用,可是BCB裡似乎沒 有這種event,能否請教各位先進是不是有其他的方法可以做到 或是是我沒看清楚。謝謝。
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-09-23 12:06:24 IP:220.138.xxx.xxx 未訂閱
可以作到類似 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.
const 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 */
}
只要自己瞭解整個 Application 的所有事件即可 > < href="http://free.greenworld.com.tw/~dllee/" target="blank">吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Beckhoff Fieldbus
------
http://www.ViewMove.com
slam3556
一般會員


發表:1
回覆:2
積分:0
註冊:2005-08-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-09-27 09:30:26 IP:211.76.xxx.xxx 未訂閱
dllee版大所說的應該可以做到pre-trigger, 但真的除了這些資料庫物件以外,其他的物件 都沒有辦法做到post-trigger嗎?
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-09-27 16:53:40 IP:220.139.xxx.xxx 未訂閱
真的有必要嗎?我認真的想了想... 大部份的事件也是在程式中去叫用而已,特別是 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-09-28 10:41:35 IP:211.76.xxx.xxx 未訂閱
版大說的沒錯 Powerbuilder就是專門針對資料庫開發用的語言 版大這番解釋,讓我對trigger又多了一層認識 我也認為並不是每個event都一定要有pre/post trigger 但是需要的原因就是希望可以確認某個動作已經完成 而這個動作又不知道該怎樣確認是否完成 所以才會就整個event來看完成與否 回應中所說可將原事件拆成三個來作 可否請版大出示大略的程式碼供小弟參考 此問題至此已有答案 感謝dllee的解答 發表人 - slam3556 於 2005/09/28 10:46:27
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-09-28 17:29:35 IP:220.139.xxx.xxx 未訂閱
參考這篇 【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
系統時間:2024-05-18 6:42:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!