C++ Builder开发点滴

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航