liz wrote:
Quote
On Thu, 15 Sep 2005 12:43:45 +0200, Wiljo wrote:
>When I derive new Forms from this dockable one,
>those forms often need to contain their own FormCreate method
No. Put all of that in the constructor.
Don't use FormCreate.
Thanks,
This is a good solution, if it were only that simple. It all comes down to the
order of execution. I would like the derived FormCreate, or constructor for that
matter, to be called before the FormCreate in the base form. When I put all my
stuff in both constructors, the base constructor is called before the derived
one. See this example:
//* In the UnitDockHost.cpp
void __fastcall TBaseDockHost::FormCreate( TObject *Sender )
{
//* Parse application components and collect
//* appropriate data from program ini file
...
}
//* In the UnitDerivedMainForm.cpp
void __fastcall TDerivedMainForm::FormCreate( TObject *Sender )
{
//* Create dockable forms
//* and do other stuff
//* Now call the base function
TBaseDockableForm::FormCreate( this );
}
This piece of example code demonstrates my problem. The derived form creates
instances of dockable Forms (Components in the application), then the base
FormCreate can be called to parse these components and read their data from an
ini file. I don't want to burden every form with reading it's stuff from the ini
file, and I don't want to burden every dockable form with an explicit call to
the base class.
I want my base code to be as abstract as possible. This base code handles
dockable forms, of any derived type, and docking hosts of three types: the main
window with docking panels, a tabbed form and a stacked form. I want the layout
of the desktop to be the same between program sessions. An ini file thus
contains the necessary information to do this, but I want the code to handle the
desktop layout hidden from these derived forms. When designing a dockable form,
the only thing I want to do is derive it from the base dockable form, and the
rest should be automatic.
Therefore I want a construction much like this:
//* In the UnitDockHost.cpp
void __fastcall TBaseDockHost::Create( TObject *Sender )
{
if( OnCreate != NULL )
{
//* Call the derived FormCreate function here
OnCreate( Sender );
}
//* Now we can parse the Application components
//* and read their stull from the ini file.
for( .... )
{
}
}
//* And in the UnitDerivedainForm.cpp
void __fastcall TDerivedMainForm::FormCreate( TObject *Sender )
{
//* Only create dockable forms here
//* or do some other stuff
}
Just writing a Create function in the base class will not work, because there is
no virtual base function to derive with this name. Therefore I want to know if
this construction is possible in another way, by maybe deriving another base
function.
thanks
Wiljo.
{smallsort}