In OOP the first method will be called when a class is instantiated is its
constructor, isn't it? How about the TForm? What is the difference between
TForm() and FormCreate()? I tried a simple application in BCB5 which has
these two methods doing the opposite thing (setting a Boolean to true in
constructor and setting it false in FormCreate()). It called the
constructor first and then the FormCreate(), therefore the result of the
Boolean is always false.
However I am debugging an application developed by someone else. The result
is the FormCreate() is always called before the constructor, so the result
is opposite to my simple application. I trace the skeleton of these two
versions and do not find any apparent difference.
Any one have idea for this happening?
Thanks in advance,
Patrick Wong
> In OOP the first method will be called when a class is
> instantiated is its constructor, isn't it?
Yes.
> How about the TForm?
The same.
> What is the difference between TForm() and FormCreate()?
OnCreate is an event that is triggered during TCustomForm's construction.
> I tried a simple application in BCB5 which has
> these two methods
I'll spare you the gory details here, since you can do a search online if
you want them as the topic has been discussed many many times before, but
you should never use the OnCreate event in C++ at all. It is a Delphi
feature that does not work properly in C++ as it can be triggered before
your descendant form's constructor is called, which is illegal in C++.
Delphi and C++ have different creation orders when it comes to creating
ancestor/descendant object instances, which is why it works fine in Delphi
but not C++.
> doing the opposite thing (setting a Boolean to true in constructor
> and setting it false in FormCreate()). It called the constructor first
> and then the FormCreate(), therefore the result of the Boolean
> is always false.
A fluke only. You can't rely on that behavior.
> However I am debugging an application developed by someone
> else. The result is the FormCreate() is always called before the
> constructor
Exactly why you should never use the OnCreate event in C++ at all.
> I trace the skeleton of these two versions
> and do not find any apparent difference.
Have a look at the OldCreateOrder property.
Gambit
http://www.bcbdev.com/articles/suggest.htm#oncreate
~ JD