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.
LVL 1
surfboredAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ephraim WangoyaCommented:

Thats how the Radio group is designed, to overcome this, do the following code

  RadioGroup1.OnClick = nil;   //remove the event before changing index
  try
     RadioGroup1.ItemIndex := 1;  //your value
  finally
     RadioGroup1.OnClick := RadioGroup1Click;  //restore the event
  end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ephraim WangoyaCommented:

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;
0
surfboredAuthor Commented:
Quick and easy, that's just the kind of answers I like!!! Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.