Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Constructor and FormCreate

52 views
Skip to first unread message

Patrick Wong

unread,
Jul 15, 2004, 9:47:08 PM7/15/04
to
Dear all,

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


Remy Lebeau (TeamB)

unread,
Jul 15, 2004, 10:13:01 PM7/15/04
to

"Patrick Wong" <patri...@computer.org> wrote in message
news:40f7330d$1...@newsgroups.borland.com...

> 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


JD

unread,
Jul 16, 2004, 12:53:48 AM7/16/04
to

"Remy Lebeau \(TeamB\)" <gambit47...@no.spam.yahoo.com> wrote:
> [...] since you can do a search online [...]

http://www.bcbdev.com/articles/suggest.htm#oncreate

~ JD

0 new messages