函式地址(不知道是否確切!) (轉)

amyz發表於2007-11-13
函式地址(不知道是否確切!) (轉)[@more@]

本問參考網友的一篇TApplication的介紹而寫的!

討論的內容是隻是個地址的東西!

假如你現在要在TStatar上顯示時間,你可能有很多的方法,現在看這種:

void __fastcall TForm1::tryidle(T * Sender, bool & Done)
{
  Form1->StatusBar1->SimpleText=DateTimeToStr(Now());
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Form1->OnlClick=tryer; 
  Application->OnIdle=tryidle;
  Form1->Button1->OnClick=Button3Click; 
}

如果你一定要問我:Sender和Done做什麼用,我告訴你,根本沒有用,只是為了湊成一個和Application->OnIdle一模一樣的東西而已!

上邊的資料取自裡的一篇文章!先邊的是我自己考慮的東西,不知道有沒有意思,如果你看了有幫助,那可別忘了謝謝那位幕後英雄啊!

其他的可以嗎!我想也是可以的,於是我就繼續,試一試TButton,就寫了幾個TButton在Form1上!

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  ShowMessage("Button3Click!");
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Form1->OnDblClick=tryer;
  Application->OnIdle=tryidle; 

  Form1->Button1->OnClick=Form1->Button3->OnClick;

}

天呢,竟然不行!怎麼辦!改!

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Form1->OnDblClick=tryer;
  Application->OnIdle=tryidle;
  Form1->Button1->OnClick=Button3Click
}

儲存在試,居然可以了!鬆了口氣!

不過為什麼不行呢!我不太明白!

查資料:TButton OnClick 是這麼解釋的!

Occurs when the user clicks the control.

__property Classes::TNotifyEvent OnClick = {read=FOnClick, write=FOnClick, stored=
IsOnClickStored};

Description

Use the OnClick event handler to respond when the user clicks the control. If the control has an associated action, and that action has an OnExecute method, the action抯 OnExecute method responds to click events unless it is superseded by an OnClick event handler.

Usually OnClick occurs when the user presses and releases the left mouse button with the mouse pointer over the control. This event can also occur when

The user s an item in a grid, outline, list, or combo box by pressing an arrow key.
 The user presses Spacebar while a button or check box has focus.
 The user presses Enter when the active fohas a default button (specified by the Default property).
 The user presses Esc when the active form has a cancel button (specified by the Cancel property).
 The user presses the accelerator key for a button or check box.

The Checked property of a radio button is set to true.
 The value of the Checked property of a check box is changed.
 The Click method of a menu item is called.

For a form, an OnClick event occurs when the user clicks a blank area of the form or on a disabled component.

TNotifyEvent 是什麼東西呢!

NotifyEvent is used for events that do not require parameters.

Unit

Classes

typedef void __fastcall (__closure *TNotifyEvent)(System::TObjectTObject* Sender);

Description

The TNotifyEvent type is the type for events that have no event-specific parameters. These events simply notify the component that a specific event occurred. For example, OnClick, which is of type TNotifyEvent, notifies the control that a click event occurred on the control.

The Sender parameter is the object whose event handler is called.  For example,.with the OnClick event of a button, the Sender parameter is the button component that is clicked.

呵呵!

看明白沒有啊!TNotifyEvent 是不需要引數的事件,那個Sender是個被呼叫的控制程式碼!明白了沒有,不過我是這麼理解的!


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-982114/,如需轉載,請註明出處,否則將追究法律責任。

相關文章