Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about handling buttons in a toolbar. 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I have a toolbar that has multiple buttons. They are in the same groupindex and they have the alup state. When i click one,the previously clicked gets unclick. Perfect.
The issue i have is on how can i monitor the state of a button? Let me explain.
I have a context popup menu that is triggered when i click the right mouse button. I have to disable that, when i click the zoom icon in my toolbar because the right mouse button zooms out.
I want to find a way to setup my autopopup back to true when the zoom icon is unchecked.
I can add the autopopup:=true to al the other clicked icons but want to know if there's a more elegant way to do that.

I hope i am making sense.
PO
 
Doing it that way can be a nightmare. Try putting a TActionList (Standard palette) on your form. Define all your actions in the ActionList:

Double-click the ActionList icon to bring up the Action Editor. Name each Action accordingly (Default name is Action1, Action2, ...) but be descriptive.

Create an OnExecute event (Action1Execute(Sender)) for each Action.

Then for each button and menu item, assign the Action property to one of the Action items. You no longer need OnClick events, so move whatever existing code you have from the OnClick events for you buttons and menu-items to the OnExecute event of each Action.

It sounds more complicated than it actually is, but that's the "more elegant way to do it" you asked for and eliminates the problems you described.

HTH

Roo
Delphi Rules!
 
Thanks, i know on how to create action list but i do not see on how it's going to tell me if i have unchecked a button.

Let's say I have a action called aZoom.
I have an onexecute event called azoomExecute that has this code:

layerpopup.autopopup:=false;
I then assign this event to my zoom button.

Now when i click to another icon ,i want to re enable layerpopup.autopopup:=true;

I can do that with all the buttons but would like to find a way to trigger that when the zoom button is up and not down.

I do not see on how actions can help me. Maybe i am missing something.
PO
 
when you click the zoom button set the form (or what ever control) has the menu to nil

if zoombutton.checked then
PopupMenu := nil;

then when ready set it back

PopupMenu := PopupMenu1;

Aaron
 
How do i do that in an efficient way? When i click on the zoom button, i disable my popup. I know on how to do that. I want a way to monitor to see if the zoom button is not checked to re enable my popup. Right now the only way i found out on how to do that is re enable the popup on all my other buttons. That means that when i click another button, it gets re enable. It's a lot of code added. If i can find a way to have the form monitor only the state of the zoom button, it would be better.
Am i making sense?
PO
 
Have you tried putting it in the ActionList.OnExecute?
Code:
procedure TForm1.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
begin
  if Action = aZoom then
    if not aZoom.Checked then
      LayerPopup.AutoPopup:= true
end;

Roo
Delphi Rules!
 
Ah....I see now...Let me try that....
Thanks...
 
Forgot to say thanks...It worked like a charm and I learned something new...
PO
 
Glad I could help - and thank you!
(I learned a couple of things myself while playing with it)

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top