Return to Sender(4)
2008-04-09 04:28:07来源:互联网 阅读 ()
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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
