I have a TPageControl with a number of TTabSheets that contain TForms (or possibly TFrames, but TForms for now).
When a tab comes into view I would like the TForm or TFrame to be notified it has come to the front. I can't find anything that does that.
I know I can get the Active TTabSheet in the OnChange
event, so I tried to add this class to the TForm:
struct iTab
{
virtual void DoIt( void ) = 0;
};
with the this in the OnChange
:
ICPTab *tab = dynamic_cast<ICPTab *>( sheet->Controls[ 0 ] );
Thinking I could use RTTI to get the iTab
pointer and call DoIt()
from the
And I get the warning:
[BCC32 Warning] Unit1.h(18): W8130 Interface 'IPTab' does not derive from IUnknown. (Interfaces should derive from IUnknown)
[BCC32 Warning] MainWindow.cpp(612): W8131 Casting Delphi style class 'TControl' to an interface. Use 'System::interface_cast<ICPTab>(cls)' instead
I am not interested in getting all of IUnknown just so that the form can use an interface.
I can get the TFrame or TForm pointer using:
TForm *tab = dynamic_cast<TForm *>( sheet->Controls[ 0 ] );
but can't call a non TForm method with this pointer. Would it be ok to call the Activate()
method?
So how do I notify the TForm or TFrame that it is now showing?
I went with the following code:
Since a form on a tabsheet never has its OnActivate method called, this works quite well.
note: the method sample is not complete, there is no call to OnDeactivate