Search code examples
delphivcldelphi-2010tcategorypanelgroup

Order of TCategoryPanel into TCategoryPanelGroup


I got a whole Delphi application with 32 differents forms for data input. I got 1 main TCategoryPanelGroup with 115 diffrents TCategoryPanel on it.

There are 6 main TCategoryPanel (main1, to main6) that we found on each forms and we add to this some specific (specific1, 2, 3, and so on) TCategoryPanel to each of them.

All forms are already prebuilt in the application, theren't built at runtime.

There's the way I do manage those forms (32 forms with an average of 10 panels of information on each)

  • Before running the application, all panels are visible false and all ordered correctly;
  • the user chose one of the 32 forms;
  • I do show (visible true) those panels in order : main1, main2, main3, specific1, specific2, main4, main5 and main6;
  • Than I show the form to the user;
  • On closing the form, I do hide (visible false) in order : main6, main5, main4, specific 2, specific 1, main3, main2 and main1;

Than the user may open another different form (from 32) and the same process goes again. But somehow, the order of panels aren't always the same that I do show (visible true) them.

Sometimes, specific1 panel comes right before main1 or even after main6. First form to get open always fine, and after opening and closing different forms, all panel orders are all mixed up.

I spent a couple of time looking on the web trying to understand the way TCategoryPanelGroup manage the order of his panels while showing and hidding them and there ya go, I Need help.

Well, the question is simple, is there different way to manage panels order on a TCategoryPanelGroup to suits my needs? Can we simply make them visible than after all rearrange the order?

So far, I focus on those 2 links for something similar but unable to get trought :

http://www.devsuperpage.com/search/Articles.aspx?G=2&ArtID=92075 http://codeverge.com/embarcadero.delphi.vcl.using/order-of-tcategorypanels-on-tcat/1066818

My MCVE

Download it here

Nb of specific panels :

  • Form #1 = 4
  • Form #2 = 2
  • Form #3 = 3
  • form #4 = 2

TEST A :

  1. Open Form #1 {okay}
  2. Close it
  3. Open Form #3 {okay}
  4. Close it
  5. Open Form #1 {not okay, since 1 more panel from the lowest nb of specific panels open yet}
  6. Close it
  7. Open Form #4 {okay} he's now the lowest nb of specific open panels with 2.
  8. Close it
  9. Open Form #3 {not okay, cause got 3 specific panels and the lowest opened by now was down to 2}
  10. Shut down the application.

TEST B :

  1. Open Form #3 {okay}
  2. Close it
  3. Open Form #4 {okay lowest nb of specific is now at 2}
  4. Close it
  5. Open Form #3 {not okay, cause got 3 specific panels and the lowest opened by now was down to 2}
  6. Close it
  7. Open Form #2 {okay since we're equal to nb of specific lowest by now which is 2}
  8. Close it
  9. Open Form #3 {not okay, cause got 3 specific panels and the lowest opened by now was down to 2. Here we have another situation since specific #2, #6 and #4 are now mixed up and also not regrouped}
  10. Shut down the application.

2 different overall situations : specific panels not regrouped and specific panels order are mixed up. I do understand what's going on before even opening form one after another but can't found out a way to fix it.


Solution

  • Allright, got it by myself

    The TCategoryPanelGroup manage the order of his TCategoryPanel with the TOP property.

    hidding (visible : false) them in reverse order and Showing (visible := true) them in order could work if you always have the same amount of panels to show in the same order.

    I found this post related to the TOP property that inspire's me : How to reorder categories in TCategoryPanelGroup (Delphi XE). In this post the solution is to give the exact TOP value from 0 for the first panel, the second one is equal to the height value of the first panel and so on.

    I figured something a lot easier by giving all panel the same TOP value before showing them... be careful, to provent panel disorder, you need to give a TOP value greater than the longest form you could have in the TCategoryPanelGroup with panels COLLAPSED to false.

    So on hiding all panels no matter the exact order and giving them TOP value := 10000 to each all is now fixed.

    RECAP :

    • All panels are invisible {no matter the order you make them invisible}.
    • All panels got the same TOP value := 10000; {greater value than the longest form}
    • Show panels in the exact order they must appear from TOP to BOTTOM;

    That's it we're done!

    My MCVE with the solution included download it here