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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:11:37+00:00 2026-05-16T05:11:37+00:00

i have create 5 dynamic buttons in 1 row and store the button info

  • 0

i have create 5 dynamic buttons in 1 row and store the button info (caption, isActive, etc) in registry. It shows the button in form when the IsActive = TRUE from registry. The result is as below (each button indicate by a * symbol):

*****

When i set the IsActive = FALSE for button2 and button4, the button being remove and left the space as below:

* ** *

Any idea to solve this problem? The source code is as below:

    procedure TfrmPOS.CreateDynamicBtn;    
    var
      Reg : TRegIniFile;
      lstKey   : TStringList;
      sKeyName : String;
      bActive  : boolean;
      btn1     : TBitBtn;
      i, k, iIcon : integer;
    begin
      lstKey    := TStringList.Create;
      Reg       := TRegIniFile.Create;
      try
        //clear bitbtn
        if ScrollBox2.ControlCount > 0 then begin
           for k := ScrollBox2.ControlCount - 1 downto 0 do begin
              with ScrollBox2.Controls[k] AS TBitBtn do begin
                Free;
              end;
           end;
        end;

sKeyName := Sysmem.RegKeyRoot+'\POSConfig\ItemSetting\';
Reg      := TRegIniFile.Create(sKeyName);
Reg.GetKeyNames(lstKey);   //button1, button2,...
for i := 0 to lstKey.Count - 1 do begin
  Reg.OpenKeyReadOnly(sKeyName);
  bActive := Reg.ReadBool(lstKey.Strings[i], 'IsActive', TRUE);
  if bActive = TRUE then begin
     //create dynamic bitbtn
     btn1 := TBitBtn.Create(self);
     btn1.Parent  := ScrollBox2;
     btn1.Height  := 82;
     btn1.Width   := 82;
     btn1.Left    := ((i mod 5) * btn1.Width);
     btn1.Top     := (Trunc((i div 5)) * btn1.Height);
     btn1.Caption := Reg.ReadString(lstKey.Strings[i], 'Caption', '');

     iIcon := Reg.ReadInteger(lstKey.Strings[i], 'IconImage', 0);
     imglstIcon.GetBitmap(iIcon, btn1.Glyph);
     btn1.Layout  := blGlyphTop;
     btn1.Name    := lstKey.Strings[i]; 
     btn1.OnClick := OnButtonClick;
  end;
  Reg.CloseKey;
end;

finally
    lstKey.Free;
    Reg.Free;
  end;
end;
  • 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-16T05:11:38+00:00Added an answer on May 16, 2026 at 5:11 am

    I suspect you wonder why the space for the second button is still there, instead of the third button filling that area.

    It’s because you’re setting the Left properties for the buttons as though all the buttons were there:

    btn1.Left := ((i mod 5) * btn1.Width);
    

    When i = 1, you skip over it because that button is invisible. But when i = 3, you calculate its position the same as you would have if button 2 had been visible. Keep a visible-button counter separate from your list iterator, and use it to position your buttons:

    BtnIndex := 0;
    Reg.OpenKeyReadOnly(sKeyName);
    for i := 0 to lstKey.Count - 1 do begin
      bActive := Reg.ReadBool(lstKey.Strings[i], 'IsActive', TRUE);
      if bActive then begin
        //create dynamic bitbtn
        btn1 := TBitBtn.Create(self);
        btn1.Parent := ScrollBox2;
        btn1.SetBounds(BtnIndex mod 5 * 82, BtnIndex div 5 * 82, 82, 82);
        Inc(BtnIndex);
    

    There are better ways to do what you want. If you have a sufficiently recent version of Delphi, use a TFlowPanel or TGridPanel. They will arrange your buttons next to each other for you automatically. If your Delphi version didn’t come with that control, then try a TToolBar instead and fill it with TToolButton controls.

    Your question actually had nothing to do with the registry, but you can make better use of the registry anyway. There’s no need to keep re-opening the same key every time. The value of sKeyName doesn’t change inside the loop, so open the key once before you enter the loop (as shown above) and then just leave it open for as long as you need it.

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

Sidebar

Related Questions

i have create 7 dynamic buttons in a scroll box. Each row need to
i have created dynamic button with code below, the button caption is too long
Does python have the ability to create dynamic keywords? For example: qset.filter(min_price__usd__range=(min_price, max_price)) I
I can't find anything anywhere(search engines, docs, here, etc) that shows how to create
We are creating dynamic text boxes and buttons inside a grid for each row.
This is what I currently have: CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON
I have to create a dialog based application, instead of old CFormView type of
I have to create a site definition for a client that must contain pre-defined
I have to create the sin function from scratch in my Comp Sci class,
i have to create an asp.net page dynamically on runtime. It should work like

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.