unit比如说:
unit1
type
Taa=class(TForm)
protected
public
ss:string;
..........
--------------------
unit2
uses unit1
type
Tbb=class(Taa)
protected
public
procedure showss;
end;
var
bb:Tbb;
implementation
{$R *.dfm}
procedure Tbb.showss;
begin
showmessage(bb.ss);//在这儿错了
end;
..............
-----------------------
要这样写bb才能使用ss呢?
unit1
type
Taa=class(TForm)
protected
public
ss:string;
..........
--------------------
unit2
uses unit1
type
Tbb=class(Taa)
protected
public
procedure showss;
end;
var
bb:Tbb;
implementation
{$R *.dfm}
procedure Tbb.showss;
begin
showmessage(bb.ss);//在这儿错了
end;
..............
-----------------------
要这样写bb才能使用ss呢?
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Taa = class
public
ss: string;
end;
Tbb = class( Taa)
public
procedure aaa;
end;
var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
a: Taa;
b: Tbb;
begin
b := Tbb.Create;
b.ss := 'test';
b.aaa;
end;{ Tbb }procedure Tbb.aaa;
begin showmessage(ss);
end;end.
begin
showmessage(Self.ss);// 改成这样
// bb对象有可能在调用这个方法时还没有创建。而Self则一定是创建对象以后才会调用的
end;