测试单元:
Unit Unit2;InterfaceUses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs;Type
   TForm2 = Class(TForm)
      Procedure FormCreate(Sender: TObject);
   Private
      { Private declarations }
   Public
      Constructor CreateText(AOwner: TComponent; TestNum: integer);
      { Public declarations }
   End;Var
   Form2: TForm2;Implementation{$R *.dfm}{ TForm2 }Constructor TForm2.UserCreateBySize(AOwner: TComponent; TestNum: integer);
Begin
   Tag:=TestNum;
   Inherited Create(AOwner);
   self.Caption := '2222222222222';
End;Procedure TForm2.FormCreate(Sender: TObject);
Begin
   self.Caption := '1111111111111';
End;End./////////////////////////////////
在主窗口的某一Button事件中调用:
   Form2 := TForm2.UserCreateBySize(application, 1);
  Form2.Show;
按道理此时Form2的窗口标题应该显示为'22222222222',而在我的系统中却显示为'11111111111111',跟踪了一下发现在构造函数中Inherited Create(AOwner);执行完了后就执行self.caption='22222222222',然后才执行OnCreate事件。
我的系统是Vista+Delphi7(Vista+Delphi2007也是同样问题)。但此问题在XP+Delphi7却不存在,为什么?

解决方案 »

  1.   

    不好意思,测试单中的构造函数名称写错了, Constructor CreateText(AOwner: TComponent; TestNum: integer); 应该写成: Constructor UserCreateBySize(AOwner: TComponent; TestNum: integer); 
      

  2.   

    不清楚……等高手回答
    个人估计是因为vista更改了api的调用什么的,可能调用方式发生了改变?
      

  3.   

    当然是这样的顺序,甚至还要从资源当中加载一些published的属性值。
      

  4.   

    事实上在我的另一台电脑上(XP+Delphi7),是执行完Inherited Create(AOwner);立即执行OnCreate事件,然后才执行self.Caption := '2222222222222'; 这一句,最后表现出来的结果是Form2的窗口标题为'222222222',而不是'1111111111'。并且,我在记忆中也一直是这样的一个执行顺序,我以前的程序也一直这么做,都没有问题。直到最近安装了一个Vista+D7,发现以前的程序有问题了,才做了以上这个测试程序。
      

  5.   

    Inherited Create之前就已经复值了,这个给谁?
      

  6.   

    Inherited Create(AOwner)之前的赋值只是一句空代码,并不影响测试。
      

  7.   

    感谢各位,问题搞定,不是Vista系统问题,是窗口属性中的OldCreateOrder在作怪。