Search code examples
delphivcltcategorypanelgroup

TabOrder of TCategoryPanel into TCategoryPanelGroup


I'm trying to add new TCategoryPanel in a TCategoryPanelGroup but I can not order the TabOrder panels. My code is like this:

function AddPanel (_AName, _ACaption: string): TCategoryPanel;
var
  ACategoryPanel: TCategoryPanel;

   ACategoryPanel: = TCategoryPanel (CategoryPanelGroup.CreatePanel (CategoryPanelGroup));
   ACategoryPanel.Name: = _AName;
   ACategoryPanel.Caption: = _ACaption;
   ACategoryPanel.Top: = 1000;

   Result: = ACategoryPanel;
end;

I call this code many times to add some panels. I tryed to set the Top property with a high value after reading this topic: Order of TCategoryPanel into TCategoryPanelGroup

But this only corrects the visible order of the panels I guess, and my problem is with the TabOrder.

I did this test:

  ACategory1 := AddPanel ('Category1', 'Category 1');
  ACategory2 := AddPanel ('Category2', 'Category 2');
  ACategory3 := AddPanel ('Category3', 'Category 3');

In the screen, the order will be:

  Category1
  Category2
  Category3

But the TabOrder will be:

  Category1 = 2
  Category2 = 1
  Category3 = 0

Any ideas?


Solution

  • I got what I wanted creating a inherited class from TCategoryPanelGroup:

    TOrderedCategoryPanelGroup = class(TCategoryPanelGroup)
    public
      procedure ReorderTabOrderByList;
    end;
    
    procedure TOrderedCategoryPanelGroup.ReorderTabOrderByList;
    var
      i: Integer;
    begin
      for i := 0 to Panels.Count - 1 do
      begin
        TWinControl(Panels[i]).TabOrder := i;
      end;
    end;
    

    Using this way:

    procedure ProcessPanelGroup(CategoryPanelGroup: TOrderedCategoryPanelGroup);
    begin
      CreatePanels(CategoryPanelGroup); //Create the PanelGroups
      CategoryPanelGroup.ReorderTabOrderByList;
    end;
    

    The responsibility of maintaining the ordering of the panels is from his parent, as it should be. I do not want to control something that will only give me more work. This way I can "set the tab order without setting the tab order".

    Maybe this could be done also inheriting the TCategoryPanelGroup.CreatePanel method. That way I will not need to call the sorting out of the object.