Solved

Retreiving toolbutton hint from OnClick procedure

Posted on 2004-03-28
7
419 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
Comment Utility

  TToolButton(Sender).hint

 Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:geobul
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks all you guys. That was quick! Shane was first and it works ( of course).
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now