Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4552792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:50:56+00:00 2026-05-21T16:50:56+00:00

i am creating code for a dialog with a radio group as part of

  • 0

i am creating code for a dialog with a radio group as part of a preferences form. Part of our code is that when the preferences form is opened, the radio group is clicked, which configures a bunch of stuff (ie if the radio button is ‘off’ then a bunch of config stuff is hidden).

What I want is to know when the user actually clicks the radio group as opposed to it being fired when the preferences dialog opens.

So the code looks like this:

(open preferences)...
rgMyGroupClick(nil)

procedure  TdlgPreferences.rgMyGroupClick(Sender:TObject)

if sender <> nil then
begin
 //do something useful
end;

But this code is also executed when the preferences dialog is opened. What should I put in there to only execute when the user actually clicks the mouse on the button?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:50:57+00:00Added an answer on May 21, 2026 at 4:50 pm

    Testing your sender

    You can test the sender in two ways:

    procedure TdlgPreferences.rgMyGroupClick(Sender:TObject)
    begin
      if sender = RadioButton1 then //do action
      else if sender = RadioButton2 then ....
    

    or you can test the type of a sender.

    procedure TdlgPreferences.rgMyGroupClick(Sender:TObject)
    begin
      if sender is TRadioButton then //do action
      else if sender is TForm then ....
    

    The is keyword tests to see if an object is of a certain type.
    Note that the test if AObject is TObject is always true because every object is derived from TObject.

    More fun with typecasting

    The fact that is tests for the object type and all ancestors can be used for other purposes as well:

    procedure TdlgPreferences.rgMyGroupClick(Sender:TObject)
    begin
      //TObject does not have a 'tag' property, but all TControls do...
      if (sender is TControl) and (TControl(Sender).Tag = 10) then ....
    

    Because of short-circuit boolean evaluation Delphi will first check (sender is TControl) and only continue if that is true. Making the subsequent test (TControl(Sender).Tag = 10) safe to use.

    If you don’t understand the construct TControl(Sender) you can read up on typecasting.
    here: http://delphi.about.com/od/delphitips2007/qt/is_as_cast.htm
    and here: http://delphi.about.com/od/oopindelphi/a/delphi_oop11.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a small code plugin which allows you to do some things with
In my code, I am creating a collection of objects which will be accessed
When creating a class that has internal private methods, usually to reduce code duplication,
I'm creating an options dialog using WPF that lists possible keys so that the
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
I know that when creating buttons, like next and previous, that the code can
I have a YUI dialog that submits a form to a Java servlet. The
i am creating login code for facebook connect on our site, however i cannot
I'm creating a settings form that is quite similar to the Visual Studio 2008
If I check out a tagged version of my source code without creating a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.