在unti2里我如此定义,implementation部分省略,差不多是赋值
unit Unit2;interface
uses
Windows, Classes, Graphics, SysUtils;
type
Ttest = class(Tobject)
private
Fa: Integer;
procedure Seta(Value: Integer);
public
constructor create;
property a: Integer read Fa write Seta;
end;
var
test: Ttest;在unit1里uses unit2,当调用test对象的方法时就出错
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
i := test.a; //这里会出错
Label1.Caption := Inttostr(i);
end;怎么觉得以前经常这么用都没事的,今天忽然就不行了,不知道哪儿出问题了,高手不吝指点啊
unit Unit2;interface
uses
Windows, Classes, Graphics, SysUtils;
type
Ttest = class(Tobject)
private
Fa: Integer;
procedure Seta(Value: Integer);
public
constructor create;
property a: Integer read Fa write Seta;
end;
var
test: Ttest;在unit1里uses unit2,当调用test对象的方法时就出错
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
i := test.a; //这里会出错
Label1.Caption := Inttostr(i);
end;怎么觉得以前经常这么用都没事的,今天忽然就不行了,不知道哪儿出问题了,高手不吝指点啊
test := Ttest.create;另:
var
test: Ttest;
建议改写:
var
test: Ttest = Nil; 这样子在调用之前可以判断一下if test = nil then test := Ttest.Create;
implementation
后面在
end.
之前,还可以定义
initialization
和
finalization
其中
initialization节当中可以用来初始化一些全局对象,finalization节当中可以对其进行释放