initialization的怪问题,在线等.....(200分)

  • 主题发起人 主题发起人 Crazyz
  • 开始时间 开始时间
C

Crazyz

Unregistered / Unconfirmed
GUEST, unregistred user!
如果在initialization中Create会提示错误码'标号没有引用存储'
但在unit1中就不会出错.在另一个程序中我也是这样写的但都不出错

unit Unit1;

interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type

TAdoc=class(Tcomponent)
private
FAdocc: TAdoConnection;
public
property Adocc: TAdoconnection read FAdocc;
constructor create(AOwner: Tcomponent);override;
end;
var
adoc: TAdoc;
implementation

{ TAdoc }

constructor TAdoc.create(AOwner: Tcomponent);
begin
inherited;
FAdocc := Tadoconnection.Create(nil); //会提示错误码'标号没有引用存储'
end;

initialization
adoc := TAdoc.create(nil);
finalization

end.
***************************************

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm2 = class(TForm)
Button1: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
adoc := TAdoc.create(nil);//可以
end;

end.
 
把nil换成AOwner或Self试试
 
to kimfeng,
我都试过了 nil,AOWner,Application

 
是不是少了一句?以下是能通过的!

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,adodb,
activeX;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
type

TAdoc=class(Tcomponent)
private
FAdocc: TAdoConnection;
public
property Adocc: TAdoconnection read FAdocc;
constructor create(AOwner: Tcomponent);override;
end;
var
adoc: TAdoc;

var
Form1: TForm1;

implementation

{$R *.DFM}

constructor TAdoc.create(AOwner: Tcomponent);
begin
inherited;
FAdocc := Tadoconnection.Create(nil); //会提示错误码'标号没有引用存储'
end;

initialization
coinitialize(nil); //你有这行吗???????
adoc := TAdoc.create(nil);
finalization

end.
 
接受答案了.
 
后退
顶部