N
netbug
Unregistered / Unconfirmed
GUEST, unregistred user!
请看以下的例子,它包括两个unit,分别为unit1与unit2:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TNum=class
public
n1:integer;
n2:string;
public
constructor create;
end;
constructor Tnum.create;
begin
n1:=111;
n2:='aaa';
end;
end.
与
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
unit1;
procedure TForm1.Button1Click(Sender: TObject);
var
num1:Tnum;
begin
num1:=tnum.create;
edit1.text:=inttostr(num1.n1);
edit2.text:=num1.n2;
num1.free;
end;
end.
但在编译unit2时,老是提示:undeclared identifier:'Tnum',但Tnum是在unit1中定义的类,
并在unit2中有uses unit1,我想问:这是为何?如何解决?
谢谢。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TNum=class
public
n1:integer;
n2:string;
public
constructor create;
end;
constructor Tnum.create;
begin
n1:=111;
n2:='aaa';
end;
end.
与
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
unit1;
procedure TForm1.Button1Click(Sender: TObject);
var
num1:Tnum;
begin
num1:=tnum.create;
edit1.text:=inttostr(num1.n1);
edit2.text:=num1.n2;
num1.free;
end;
end.
但在编译unit2时,老是提示:undeclared identifier:'Tnum',但Tnum是在unit1中定义的类,
并在unit2中有uses unit1,我想问:这是为何?如何解决?
谢谢。