1

I'm using a TPageControl with 2 TTabSheet (ModifyTab and DeleteTab) and I have code in OnShow and OnHide events for both tabs . I was thinking that when I clicks anyone of these tabs, OnHide event of the selected Tab occurs first and clicked tab´s OnShow event later but it´s the opposite. Why's that?

I create a TDictionary in every OnShow event and free in every OnHide but compiler raises an exception because it executes OnShow event, then executes OnHide and then I can't use the Dictionary because it's nil and destroyed.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
fuentes
  • 11
  • 3
  • Sounds like the new TabSheet is shown before the previous TabSheet is hidden (I don't have access to Delphi right now to confirm in its source). Try using the `TPageControl`'s `OnChanging` and `OnChange` events instead. Are you using a single dictionary for both TabSheets, or does each TabSheet have its own dictionary? Please show your actual code you are having trouble with. The order of the `On(Show|Hide)` wouldn't be a problem if you were using separate dictionaries. You could use the `TTabSheet.Tag` to track with dictionary belongs to which TabSheet. – Remy Lebeau Feb 12 '19 at 21:00
  • 6
    Just nitpicking: the compiler isn't executing anything, it is just making the executable out of your source code. Also, it isn't even responsible for this behaviour; instead, this happens because the VCL page control is designed this way. – Andreas Rejbrand Feb 12 '19 at 21:05
  • The compiler isn't executing anything, that's a big true. I'm trying to create a dictionary for each tab and I think it's my solution. Thanks. – fuentes Feb 12 '19 at 21:19
  • 1
    Let me se if I understand you correctly. You have one global TDictionary object whose contents should depend on which TTabSheet is being shown. But you are experiencing problem because when you are switching tabs the new tabs gets shown before old tabs gets hidden. Right? Well since the contents of TDictionary are dependent on each tab have you ever considered adding TDictionary object to each tab instead of using a global one. This would allow you to avoid any troubles of order in which your tabs are shown/hidden. In fact you would even get a chance to show multiple tabs at the same time – SilverWarior Feb 12 '19 at 21:50
  • Why not use the OnChange and/or the OnChanging event of TPageControl instead. Then the order of Hide/Show is unimportant. – Dsm Feb 13 '19 at 11:14

0 Answers0