Return to Sender(4)

2008-04-09 04:28:07来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

OnClick event handler

File1

0

--

MainItem1

1

SpeedButtonClick

MainItem2

2

SpeedButtonClick

MainItem3

3

SpeedButtonClick

MainItem4

4

SpeedButtonClick

PopupItem1

1

SpeedButtonClick

PopupItem2

2

SpeedButtonClick

PopupItem3

3

SpeedButtonClick

PopupItem4

4

SpeedButtonClick

Figure 3: Setting the values of properties for the sample application''''s SpeedButton and MenuItem components.

Note that all the buttons and menu items have the same event handler, namely SpeedButtonClick (see Figure 4). This procedure is called from any of the SpeedButtons or menu items on the form (except MenuItem File1). It references two external procedures, PushButton and ReleaseButton.

procedure TForm1.SpeedButtonClick(Sender: TObject);

var

A : Integer;

begin

if Sender is TSpeedButton then

if TSpeedButton(Sender).Down then

PushButton(Sender)

else

ReleaseButton(Sender)

else

for A := 0 to ComponentCount-1 do

if Components[A] is TSpeedButton then

with Components[A] as TSpeedButton do

if Tag = TComponent(Sender).Tag then

begin

Down := not Down;

if Down then

PushButton(Self.Components[A])

else

ReleaseButton(Self.Components[A]);

end;

end;

Figure 4: Referencing PushButton and ReleaseButton with the SpeedButtonClick procedure.

SpeedButtonClick first determines which object sent the event. If it''''s a TSpeedButton, it simply passes that object to the PushButton or ReleaseButton procedure, depending on the button''''s state (up or down). These procedures simply allow convenient spots for the messages to be handled. In the following example, the Caption of Label1 is set to report the event that occurred:

procedure TForm1.PushButton(Sender: TObject);

begin

Label1.Caption :=

TComponent(Sender).Name '''' was clicked.'''';

end;

procedure TForm1.ReleaseButton(Sender: TObject);

begin

Label1.Caption :=

TComponent(Sender).Name '''' was released.'''';

end;

If the Sender of the event is not one of the buttons, we must determine which button to click. This is where the

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Data-Browse型Data-Aware控件的制作

下一篇:ktv 系统设计经验