Search code examples
user-interfacedelphicomponentsvcldelphi-2009

How to dynamically add buttons to TCategoryPanelGroup?


Has anybody experience with Delphi 2009's TCategoryPanelGroup component and specifically with dynamically adding buttons to category panels?

I can't get it to work properly. Either the buttons do not appear or the alignment is screwed up. Basic outline of what I want to do:

procedure AddButton (const Caption, Group : String);
const 
  ButtonSize = 55;
  Border = 10;
var
  CategoryPanel : TCategoryPanel;
  Button : TButton;       
begin
  CategoryPanel := FindCategoryPanel (CategoryPanelGroup, Group);
  CategoryPanel.Height := CategoryPanel.Height + ButtonSize + Border;
  Button := TButton.Create (CategoryPanel);
  Button.Parent := CategoryPanel;
  Button.Width := ButtonSize;
  Button.Height := ButtonSize;
  Button.Left := 27;
  Button.Top := CategoryPanel.ClientHeight - Border - ButtonSize;
end;

Any hints?


Solution

  • Problem was the way I specified the top coordinates.

    I changed it to something like

    ButtonCount := CategoryPanel.ComponentCount - 2;
    Button.Top := Border + ButtonCount * (ButtonSize + Border);
    CategoryPanel.ClientHeight := Border + (ButtonCount+1) * (ButtonSize + Border);
    

    and it works.

    Don't know exactly what caused the problem.