unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
iii : integer;
public
{ Public declarations }
procedure showiii;
end;var
Form1: TForm1;
d : TA;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
showiii;
d.ShowI('hello world');end;procedure TForm1.showiii;
begin
iii := 55;
showmessage('ok');
end;end.unit1 的内容。unit Unit2;interface
type
TA = class
private
i : string;
public procedure showI(x : string);end;implementation
uses dialogs;
procedure TA.showI(x : string);
begin
i := x;
showmessage(i);
end;end.unit2 的内容。运行后程序出错,读写一段地址错误。 给我的感觉,就像TA类的public 方法 showI 不能访问它的private 成员i 一样。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
iii : integer;
public
{ Public declarations }
procedure showiii;
end;var
Form1: TForm1;
d : TA;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
showiii;
d.ShowI('hello world');end;procedure TForm1.showiii;
begin
iii := 55;
showmessage('ok');
end;end.unit1 的内容。unit Unit2;interface
type
TA = class
private
i : string;
public procedure showI(x : string);end;implementation
uses dialogs;
procedure TA.showI(x : string);
begin
i := x;
showmessage(i);
end;end.unit2 的内容。运行后程序出错,读写一段地址错误。 给我的感觉,就像TA类的public 方法 showI 不能访问它的private 成员i 一样。
begin
showiii;
d := TA.Create;//d需要创建
d.ShowI('hello world');
end;procedure TForm1.showiii;
begin
iii := 55;
showmessage('ok');
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
d.Free;
end;
定义个类
MyClass=Class
private
.
.
.
public
.
.
.
end;类的引用
var aClass:TMyClass;
begin
aClass:=TMyClass.Create;(实例化)
aClass.方法;
aClass.free;(释放)
end;