Solved

Retreiving toolbutton hint from OnClick procedure

Posted on 2004-03-28
7
425 Views
Last Modified: 2010-04-05
I have a number of toolbars each with a number of buttons( 114 buttons altogether !). I need to find out which button has been clicked from a common OnClick procedure. I thought it should be easy enough ( and probably is if only I knew what I was doing). The toolbars have a horizontal set of buttons on each and the toolbars are stacked vertically. I can't seem to access any of the properties which might be of use eg left,top,index. My last idea was to set the hint on each button and find out that way. The hint shows OK on the form at runtime, but is blank if I do

   showmessage(hint); in the onclick procedure.

This is driving me mad as I am sure you will all be shouting out the answer, but I just can't see it.

Thanks
0
Comment
Question by:jixe
7 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10699709

  TToolButton(Sender).hint

 Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10699718
You could go through and set all the tag properties of you buttons - 0 - 114

 the assign the same OnCLick event to them

ShowMessage(Inttostr( TToolButton(Sender).Tag));

 Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10700078
You could go through and set all the tag properties of your buttons to the values ( 0 - 114)

and  then assign the same OnCLick event to them

then you could look at the tag property to determine what button was pushed

ShowMessage(Inttostr( TToolButton(Sender).Tag));


case TToolButton(Sender).tag of
 0: ShowMessage('Button 0 ');
 1: ShowMessage('Button 1 ');
 2: ShowMessage('Button 2 ');
 etc.
end;

 Shane
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 17

Expert Comment

by:geobul
ID: 10701708
Hi,

You may also use buttons names this way:

procedure TForm1.MyCommonToolButtonClick(Sender: TObject);
begin
  if (Sender is TToolButton) then begin
    with (Sender as TToolButton) do begin
      if Name = 'ToolButton1' then begin
        ShowMessage('ToolButton1 was pressed');
      end;
      if Name = 'ToolButton2' then begin
        ShowMessage('ToolButton2 was pressed');
      end;
      // ...
    end;
  end;
end;

Regards, Geo
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10701731
Thats alot of if thens (120 to be exact)....

 how about

procedure TForm1.MyCommonToolButtonClick(Sender: TObject);
begin
  if (Sender is TToolButton) then
    with (Sender as TToolButton) do      
      if Name = 'ToolButton'  + TToolButton(Sender).Tag then
        ShowMessage('ToolButton' + IntToStr(TToolButton(Sender).Tag ) + 'was pressed');
end;


Shane

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10701831
as shanes first comment:

procedure TForm1.ToolButtonClick(Sender: TObject);
begin
  if (sender is TToolButton) then
    showmessage(TToolButton(sender).Hint);
end;
0
 

Author Comment

by:jixe
ID: 10702114
Thanks all you guys. That was quick! Shane was first and it works ( of course).
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question