事件狀態中加入含有變數之外的指令 |
答題得分者是:jow
|
gyfatty
一般會員 發表:6 回覆:13 積分:8 註冊:2006-10-18 發送簡訊給我 |
小弟這幾天遇到的問題:
發現當在特殊的狀態下呼叫副程式 產生了些許錯誤 如下 1.下為在CPP中的CODE [code cpp] void __fastcall TForm1::MouseDown( TMouseButton Button2, TShiftState Shift2, int X, int Y) { if ((Button2 == mbLeft)) { } else { } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TForm1::FormMouseDown(TMouseButton Button,TShiftState Shift, int X, int Y); } //--------------------------------------------------------------------------- [/code] 2.下為宣告在.H中的CODE [code cpp] void __fastcall TForm1::MouseDown( TMouseButton ,TShiftState , int X, int Y); [/code] 在下想在FormMouseDown的事件中 呼叫一函式MouseDown 是否有人有經驗於此方面 可否為小弟解答 感激不盡 ~~! 回 jow兄: 可以在解釋清楚一點嗎 由於在MouseDown函式中 在下會用到 Button2 == mbLeft 所以在MouseDown的宣告應當為? |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
這是定義在Vcl Controls.pas中的程式碼.
procedure TControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Assigned(FOnMouseDown) then FOnMouseDown(Selfm Button, Shift, X, Y); end; 想想看你在事件處理程序內再 Call MouseDown(), 會發生什麼情況? |
gyfatty
一般會員 發表:6 回覆:13 積分:8 註冊:2006-10-18 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
在Vcl物件繼承的定義中,到了 TControl 這一層時開始處理滑鼠的動作,
也就是接收系統送來滑鼠動作引發的訊息,例如: procedure TControl.WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN; 然後在 procedure TControl.WMLButtonDown(...)中會叫用 TControl.DoMouseDown(Message, mbLeft, []); 接著 TControl.DoMouseDown(...) 中再叫用 TControl.MouseDown(); 最後 TControl.MouseDown() 會以 Enevt 的方式通知使用端. procedure TControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin //檢查使用端是否Hook event handler, 為真則將相關參數傳給使用端定義的 //Event Handler. if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X, Y); end; 所以如果你在 Enevt Handler 中再叫用同一物件之 MouseDown 將會引發無窮迴圈. 另外你也可以利用 TShiftState來判斷滑鼠按鍵是否被按下了. type TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble); --------- 引 用 ------------------------------------------- 在下想在FormMouseDown的事件中 呼叫一函式MouseDown
編輯記錄
jow 重新編輯於 2007-09-26 15:24:12, 註解 無‧
|
gyfatty
一般會員 發表:6 回覆:13 積分:8 註冊:2006-10-18 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
(1)改寫 dynamic method.
protected: DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y); (2)定義自己的 MouseDown Event [code cpp] //--------------------------------------------------------------------------- #ifndef fMainH #define fMainH //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />//--------------------------------------------------------------------------- typedef void __fastcall (__closure *TMyMouseEvent)(TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y, WideString S); class TForm1 : public TForm { __published: TLabel *Label1; private: TMyMouseEvent FOnMyMouseDown; void __fastcall DO_ON_MYMOUSEDOWN(TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y, WideString S); protected: DYNAMIC void __fastcall MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y); public: // User declarations __fastcall TForm1(TComponent* Owner); __property TMyMouseEvent OnMyMouseDown={read=FOnMyMouseDown, write=FOnMyMouseDown}; }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif //================================================== //--------------------------------------------------------------------------- #include #pragma hdrstop #include "fMain.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner) { FOnMyMouseDown = &DO_ON_MYMOUSEDOWN; } //--------------------------------------------------------------------------- void __fastcall TForm1::MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y) { if (!FOnMyMouseDown)TForm::MouseDown(Button, Shift, X, Y); else if (Button == mbLeft) { FOnMyMouseDown(this,Button, Shift, X, Y, "Left Mouse Button Down."); } else if (Button == mbRight) { FOnMyMouseDown(this,Button, Shift, X, Y, "Right Mouse Button Down."); } } //--------------------------------------------------------------------------- void __fastcall TForm1::DO_ON_MYMOUSEDOWN(TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y, WideString S) { Label1->Caption = S; } //--------------------------------------------------------------------------- [/code] ===================引 用 gyfatty 文 章=================== 2.下為宣告在.H中的CODE [code cpp] void __fastcall TForm1::MouseDown( TMouseButton ,TShiftState , int X, int Y); [/code] |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |