Link to home
Start Free TrialLog in
Avatar of surfbored
surfboredFlag for United States of America

asked on

Change Radio Group Without Firing OnClick

I have a radio group that has an onClick event that works correctly. However, when I change the itemIndex value through code, the onClick event fires too. How can I suppress the unwanted onClick (which in my mind should actually be an "onChange" event) event?

Thanks for any ideas.
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

There are other more complex methods you could use as well. Adding a variable to indicate when you are manually changing the ItemIndex

  eg
   private
      FIndexChanging: Integer;
 
   protected
      property IndexChanging: Boolean read GetIndexChanging write SetindexChanging;
   end

function TForm1.GetIndexChanging: boolen
begin
  Result := FIndexChanging>0;
end;

procedure TForm1.SetIndexChanging(value: boolean);
begin
  if Value then
    Inc(FIndexChanging)
  else if FIndexChanging >0 then
    Dec(FIndexChanging) ;
end;


TForm1.RadioGroup1Click(Sender: TObject);
begin
  if IndexChanging then
   Exit;

  ..........continue with your code
end;

//when changing index

  IndexChanging := True;
  try
     RadioGroup1.ItemIndex := 1;  //your value
    ................
  finally
     IndexChanging := False;
  end;
Avatar of surfbored

ASKER

Quick and easy, that's just the kind of answers I like!!! Thanks!