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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Groupindex question

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
If i set all my buttons in a toolbar with the same groupindex, they act as radio buttons.

Now if I create another toolbar and use the same groupindex, they do not talk to each other. That means that if i click a button in one toolbar and another one is already pressed in the opposite toolbar, it will not go back up.

Is there a way i can make that too work?
Thanks.
PO
 
I am assuming that when you say buttons you mean TSpeedButton controls.

Ensure that the AllowAllUp property is set to TRUE for all your TSpeedButton controls.

Code a private procedure similar to
Code:
procedure TForm1.DeselectSpeedButtonsInToolBar(toolbar: TToolBar; groupIndex: integer );
// Deselects all the Speed Buttons in the specified toolbar with the specified Group Index.
var
  x: integer;
  control: Tcontrol;
begin
  for x := 0 to toolbar.controlCount - 1 do begin
    control := toolbar.controls[x];
    if control is TSpeedButton then
      if (control as TSpeedButton).GroupIndex = groupIndex then
        (control as TSpeedButton).Down := false
  end;
end;
Add to the OnClick event handler for ToolBar1 something similar to
Code:
procedure TForm1.SpeedButtonsInToolBar1Click(Sender: TObject);
begin
  DeselectSpeedButtonsInToolBar( ToolBar2, (Sender as TSpeedButton).groupIndex );
end;
and add to the OnClick event handler for ToolBar2 something similar to
Code:
procedure TForm1.SpeedButtonsInToolBar2Click(Sender: TObject);
begin
  DeselectSpeedButtonsInToolBar( ToolBar1, (Sender as TSpeedButton).groupIndex );
end;
When a SpeedButton in ToolBar1 is clicked all speed buttons in ToolBar2 that have the same GroupIndex as the selected SpeedButton in ToolBar1 are unselected (i.e. have their Down property set to FALSE. And likewise for ToolBar2.

Andrew
Hampshire, UK
 
Thanks Andrew. No I was using regular buttons, not speedbuttons. Let me look at your code and I may be able to adapt it. I am using the StpTBX library to add toolbars and buttons.
Really appreciate it.
Pierre
 
when you click a button on toolbar 1 clear toolbar 2.

var i: integer;
begin
for i := 0 to SpTBXToolbar2.Items.Count - 1 do
SpTBXToolbar2.Items.Checked := False;
end;

when you click a button on toolbar 2 clear toolbar 1.

var i: integer;
begin
for i := 0 to SpTBXToolbar1.Items.Count - 1 do
SpTBXToolbar1.Items.Checked := False;
end;

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top