Board index » cppbuilder » BDS2006 and FormCreate(TObject *Sender)

BDS2006 and FormCreate(TObject *Sender)


2006-01-28 02:46:34 AM
cppbuilder2
Is it still the recommended procedure to not use the FormCreate( ) in BDS
2006 the same as it was in previous version of BC++B?
Thanks
Larry Johnson.
 
 

Re:BDS2006 and FormCreate(TObject *Sender)

"LarryJ" < XXXX@XXXXX.COM >wrote in message
Quote
Is it still the recommended procedure to not use the FormCreate( )
in BDS 2006 the same as it was in previous version of BC++B?
Yes.
Gambit
 

Re:BDS2006 and FormCreate(TObject *Sender)

LarryJ wrote:
Quote
Is it still the recommended procedure to not use the FormCreate( ) in
BDS 2006 the same as it was in previous version of BC++B?
Yes.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"So I rang up a local building firm, I said 'I want a skip outside
my house.' He said 'I'm not stopping you.'" -- Tommy Cooper
 

{smallsort}

Re:BDS2006 and FormCreate(TObject *Sender)

Why not? I never had problems with initializations in FormCreate, and I
always thought that a Forms constructor runs before all elements of a
form are created.
What did I miss?
Richard Kaiser
Remy Lebeau (TeamB) schrieb:
Quote
"LarryJ" < XXXX@XXXXX.COM >wrote in message
news:43da69c0$ XXXX@XXXXX.COM ...


>Is it still the recommended procedure to not use the FormCreate( )
>in BDS 2006 the same as it was in previous version of BC++B?


Yes.


Gambit


 

Re:BDS2006 and FormCreate(TObject *Sender)

"Richard Kaiser" < XXXX@XXXXX.COM >wrote in message
Quote
Why not?
For the same reason as in earlier versions - because it produces illegal
behavior in C++ as it can be triggered before the constructor. The same
goes for the OnDestroy event - it can be triggered after the destructor.
Quote
I never had problems with initializations in FormCreate
Then consider yourself fortunate. Many other people have not been.
Quote
I always thought that a Forms constructor runs before all elements
of a form are created.
It does - usually. But you have to understand that the VCL is written in
Delphi Pascal, not C++. Even when used in a C++ environment, a VCL object
follows the Delphi creation model, not a C++ model. In Delphi, the creation
order is reverse from the creation order in C++. In Delphi, a descendant
class constructor is called before a base class constructor. In C++, the
opposite is true - a base class constructor is called before a descendant
class constructor.
The OnCreate event handler is directly called by the TCustomForm
constructor. If you assign the event handler at design-time, then the event
handler is a member of the descendant form class. In Delphi, all is well
because the descendant class exists by the time the event handler is called,
so accessing a descendant class member from a base class constructor is
legal. But in C++, the descendant class may not have been created yet when
the event is triggered, so the event handler member is not available yet.
But the compiler allows it anyway because the code was compiled in a Pascal
compiler. Hense the illegal behavior in C++ - a base class can never access
a descendant class member, because it dos not exist yet.
Gambit
 

Re:BDS2006 and FormCreate(TObject *Sender)

Quote

Yes.

From BDS help for TCustomForm.OnCreate:
"Use of the OnCreate event is discouraged in C++ code because it can
interact badly with the form's constructor (see OldCreateOrder). It is
recommended that you override the form constructor instead."
Mark