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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:07:45+00:00 2026-05-24T08:07:45+00:00

I am dynamically creating buttons from an array that is dynamically loaded. I am

  • 0

I am dynamically creating buttons from an array that is dynamically loaded. I am storing a piece of needed information in the buttons hint.

    procedure TForm3.CreateAppButton(sBtnCapt: string);
var
    hIcon: THandle;
    nIconId: DWORD;
    Icon: TIcon;
    NewButton: TSpeedButton;
    PicConvert: TBitmap;
    sPathNew: string;
    AppData: TAppDetails;
begin
    AppData := TAppDetails.Create(sBtnCapt);
    NewButton := TSpeedButton.Create(self);
    with NewButton do
    begin

        Width := 67;
        Height := 50;
        Left := (Width + 5) * (self.ControlCount - 1);

        Top := 5;
        Parent := self;
        Caption := AppData.Caption;
        Name := AppData.ButtonName;
        Font.Size := 7;
        // extract a 16x16 icon for display on the buttom
        sPathNew := '';
        sPathNew := sPath + AppData.Exe;
        if PrivateExtractIcons(PChar(sPathNew), 0, 16, 16, @hIcon, @nIconId, 1, LR_LOADFROMFILE)
          <> 0 then
            try
                PicConvert := TBitmap.Create;
                Icon := TIcon.Create;
                try
                    Icon.Handle := hIcon;
                    PicConvert.Width := Icon.Width;
                    PicConvert.Height := Icon.Height;
                    PicConvert.Canvas.Draw(0, 0, Icon);
                    Glyph := PicConvert;
                finally
                    Icon.Free;
                    PicConvert.Free;
                end;
            finally
                DestroyIcon(hIcon);

            end;
        OnMouseDown := btnMouseDown;
        Hint := AppData.Exe;
        ShowHint := False;
        Layout := blGlyphTop;
        AppData.Free;
    end;
end;

Where my issue arises is on the mouse down event. I want to somehow use the information stored in the buttons hint property to trigger the needed action. You can see what I am trying to in the left click and where I am coming from in the right click. Designing the right click way would require me to put in ~80 it also requires that I declare each button on the form so that I can build and compile.

procedure TForm3.btnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
    X, Y: Integer);
var
    sApp: string;
    AppData: TAppDetails;
begin
    sApp := '';
    if Button = mbLeft then
    begin
        sApp := btnFoo.Hint; 
        ShellExecute(self.Handle, 'open', PChar(sApp), nil, nil, SW_SHOWNORMAL);            
    end
    else if Button = mbRight then
    begin
        if Sender = btnCC3 then
        begin
            sApp := 'CaseClaims3.exe';
        end
        else if Sender = btnODBC then
        begin
            sApp := 'ODBCMgr.exe';
        end
        else if Sender = btnCredMaint then
        begin
            sApp := 'CreditorMaint';
        end;
        AppData := TAppDetails.Create(sApp);
        ShellExecute(self.Handle, 'open', PChar(AppData.Wiki), nil, nil, SW_SHOWNORMAL);
        AppData.Free;
    end;
end;

Can anyone point me in a direction to dynamically use the mousedown event without declaring the component ahead of time? Appdata is a separate pas file containing all the needed information on each application in case anyone is wondering.

Also please forgive my rather horrendous code, I know it could use a lot of work.

  • 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-24T08:07:46+00:00Added an answer on May 24, 2026 at 8:07 am

    I agree that you should not use the Hint property. Not least because you may at some point in time wish to use the Hint property for something else. I am also somewhat dubious of solutions that use Tag.

    I think I would use an instance of TDictionary<TSpeedButton,TAppPaths> to map between buttons and the application details. Here I’m imagining that TAppPaths is a record containing two strings, one for the left click and one for the right click, e.g.

    TAppPaths= record
      Left: string;
      Right: string;
    end; 
    

    For sake of argument, let us suppose that this instance is called ButtonDetails.

    When ever you add a new button you write code like this:

    AppPaths.Left := AppDetails.Exe;
    AppPaths.Right := AppDetails.SomeOtherFunction;
    ButtonDetails.Add(NewButton, AppPaths);
    

    Then in the form’s mouse event handler you write it like this:

    AppPaths := ButtonDetails[Sender as TSpeedButton];
    

    And now AppPaths has both paths ready for you to use.

    This idea can easily be extended to include as much information as you like in the TAppPaths record.

    As an aside, I think you should be handling MouseUp rather than MouseDown since in Windows, buttons are clicked when you release the mouse button rather than when you press it.

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

Sidebar

Related Questions

I have an ASPX page that is dynamically creating a gridview from a database
I'm new to iPhone dev. My app is dynamically creating buttons, following from my
I am dynamically creating forms from a JSON object that I fetch with a
I have an array of radio button from where i am creating radio buttons
I am creating a system where content is loaded dynamically from a JSON file.
I am dynamically creating panels based on information i get from an XML file
I just found out that in FF, if you are dynamically creating an OPTION
I am dynamically creating buttons on iPhone app. UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn
I am creating some link buttons dynamically and try to access them in some
I am creating some buttons dynamically and assigning them IDs. When ever someone clicks

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.