C++ Builder开发点滴

类别:编程语言 点击:0 评论:0 推荐:

2004-10-20 星期三
1、窗体的OldCreateOrder属性。

如果要问你,窗体类的构造函数和OnCreate事件中的代码哪个先执行,你可能会毫不犹豫的回答肯定是构造函数的代码先执行。事实上并非如此,最近在使用窗体继承时就碰到这样一个问题。我首先定义了一个基本窗体TChildBaseForm,然后以该窗体作为基础以继承方式创建窗体TUserInfoForm。在跟踪程序的时候发现,竟然是TUserInfoForm窗体的OnCreate事件处理代码先执行,然后才执行构造函数的代码。

为什么会出现这样的情况呢?后来查找TForm的帮助,发现TForm有这样一个属性OldCreateOrder,看看帮助是如何说明的:

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

This timing 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.

本文地址:http://com.8s8s.com/it/it26432.htm