Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI FormShow Event and Constructor order of execution

Status
Not open for further replies.

leit0050

Technical User
Sep 4, 2007
29
US
Hello,
OK, so I am upgrading from a program that was built on C++ builder 4 and I am using builder 2007. I am curious that I may have something wrong with the settings in my IDE because this program is behaving differently than the original.
Essentially, I am working with an MDI (multiple document interface) program. Each MDI child is created using a pointer and a new operator. What happens in the original code is that one form is used for the child window...however it is sized 3 different ways. The original programmers changed the pixel sizes in the constructor of the MDI child. In the constructor, they only setup placeholders for what the new pixels should be, they do not write them to components.
To write to components, they use the ShowForm event. The problem is, that the ShowForm function executes BEFORE the constructor is made. It looks like the developers had the constructor execute first then the ShowForm Event. Is there any way to reverse this order? Is it a setting in the IDE somewhere?

Thanks
 
I'm guessing here but what the original programmer(s) may have done is created the forms in the IDE, then linked them to the main form using the "Include Header Unit" on the IDE and in the project's options auto included the forms. I don't know if these options still exist in the newest Builders.

Once these forms' headers are included and the forms auto-created, it would have unnecessary to recreate them using the new operator so why they did that, I can't guess.

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Hi,
I don't think I phrased the question quite right...because I posted the wrong information. The MDI function OnShow is called which is aliased as the event FormShow in my program. For an MDI program, when is OnShow called? Also, I don't even see anywhere in the program where they use

mdi_child_pointer->Show();

Does the show happen the instant new is used to allocate memory for this object?

Thanks
 
Help File said:
When a form is being created and its Visible property is true, the following events occur in the order listed:

1. OnCreate
2. OnShow
3. OnActivate
4. OnPaint

Note: Use of the OnCreate event is discouraged in C++Builder because it can interact badly with the form’s constructor (see OldCreateOrder). It is recommended that you override the form constructor instead.

When OldCreateOrder is false (the default) the OnCreate event occurs after all constructors are finished and the OnDestroy event occurs before any destructors are called.

This differs from C++Builder 1, where the OnCreate event occurred when the TCustomForm constructor executed and the OnDestroy event occurred when the TCustomForm destructor executed. Applications that require the OnCreate event and OnDestroy events to occur from the constructor and destructor of the form can set OldCreateOrder to true.

I don't know if this will help or not. I also don't know if this has changed yet again in the new Builder (2006/2007).


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top