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 7660477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:28:14+00:00 2026-05-31T13:28:14+00:00

My application uses a TButtonGroup control. I assign to each button an event handler:

  • 0

My application uses a TButtonGroup control. I assign to each button an event handler: doClick. By assigning information to each button (Pointer (i)) I can figure out which button was called. This is the code:

procedure TVector_Menu.Synchronize (rows, cols: Int32);
var btn: TGrpButtonItem; 
    i: Int32;
begin
   ButtonGroup.Items.Clear;
   Self.Rows := rows;
   Self.Cols := cols;
   for i := 0 to rows * cols - 1 do
   begin
      btn := Buttongroup.Items.Add;
      btn.Data       := Pointer (i);
      btn.ImageIndex := i;
      btn.OnClick    := doClick;
   end; // for
   Self.ClientHeight :=  4 + rows * ButtonGroup.ButtonHeight;
   Self.ClientWidth  := 22 + cols * ButtonGroup.ButtonWidth;
end; // Synchronize //

procedure TVector_Menu.doClick (Sender: TObject);
var btn: TGrpButtonItem; 
    i, r, c: Int32;
begin
   btn := (Sender as TGrpButtonItem); // @@@ TButtonGroup
   i := Int32 (btn.Data);
   get_rc (i, r, c);
   if Assigned (FOnClick)
      then FOnClick (Sender, @FButton_Matrix [r, c]);
end; // doClick //

When doClick is called I get an Invalid Typecast at the line labeled ‘@@@’. The typecast is correct when I use TButtonGroup for btn as well as in the typecast, but this one does not contain a data property and that would not have been of much use anyway.

As a Test I assigned an OnClick event handler to the TButtonGroup control and I noticed that when I click a button, first the button event handler is called and next the TButtonGroup, containing the button, event handler.

Question: is there a way to find out which button of a TButtonGroup was clicked?

Using Delphi XE on Windows 7/64

  • 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-31T13:28:15+00:00Added an answer on May 31, 2026 at 1:28 pm

    You get an invalid typecast exception because Sender is in fact the TButtonGroup and is not a TGrpButtonItem. What this means is that you need to use a different event handler for each button if you are going to use TGrpButtonItem.OnClick.

    In your situation it is clear that you should use the TButtonGroup.OnButtonClicked event which does provide the button index.

    There is a potential pitfall here, however, that you need to make sure you avoid. The documentation states:

    Occurs when a button is clicked, if the OnClick event is not present.

    In other words the OnButtonClicked event will only fire if you have not assigned an OnClick event handler for either the button group or the button item.

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

Sidebar

Related Questions

My application uses MS access database to save some sensitive information. Though that information
My application uses a large amount of Panda objects. Each Panda has a list
My application uses the Trace object to log information. The information is captured in
My application uses Google to search for information and retrieves it. After a few
My application uses UITabBarController with 4 tabs. Each tab will have a UIWebView along
Our application uses SQL Server Reporting Services and allows users to add custom filters
Our application uses Hibernate with Sql Server 2005. Being a DBA, I am not
My application uses several threads with well-defined names (i.e. not a thread pool with
Our application uses a SQL Server back-end with many stored procedures. Recently, while trying
My application uses a Spring DefaultMessageListenerContainer to process incoming messages. The main method of

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.