A
awfigsk
Unregistered / Unconfirmed
GUEST, unregistred user!
源代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMySub = class(TBase)
protected
procedure invokeFShowname;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMySub }
procedure TMySub.invokeFShowname;
var
a:TBase;
b:TMySub;
begin
a:=TBase.Create;
a.showname
//这里为何不能使用a.showname?
a.name:='abcd'; //这里为何不能使用a.showname
b:=TMySub.Create;
b.showname;
b.name:='aaa';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a:TBase;
b:TMySub;
begin
a:=TBase.Create;
a.showname
//这里为何不能使用a.showname?
a.name:='abcd'; //这里为何不能使用a.showname
b:=TMySub.Create;
b.showname;
end;
end.
==========================Unit2===============
unit Unit2;
interface
type
TBase = class
protected
name:string;
procedure showname();virtual;
end;
implementation
{ TBase }
procedure TBase.showname;
begin
showmessage('name='+name);
end;
end.
为何上面二处都不能使用protected里面的字段和方法?第一处在派生类TMySub中的方法里面调用父类的方法,为何不行呢?对可见性的概念有些糊涂了,还请高手指点,谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMySub = class(TBase)
protected
procedure invokeFShowname;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMySub }
procedure TMySub.invokeFShowname;
var
a:TBase;
b:TMySub;
begin
a:=TBase.Create;
a.showname
//这里为何不能使用a.showname?
a.name:='abcd'; //这里为何不能使用a.showname
b:=TMySub.Create;
b.showname;
b.name:='aaa';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a:TBase;
b:TMySub;
begin
a:=TBase.Create;
a.showname
//这里为何不能使用a.showname?
a.name:='abcd'; //这里为何不能使用a.showname
b:=TMySub.Create;
b.showname;
end;
end.
==========================Unit2===============
unit Unit2;
interface
type
TBase = class
protected
name:string;
procedure showname();virtual;
end;
implementation
{ TBase }
procedure TBase.showname;
begin
showmessage('name='+name);
end;
end.
为何上面二处都不能使用protected里面的字段和方法?第一处在派生类TMySub中的方法里面调用父类的方法,为何不行呢?对可见性的概念有些糊涂了,还请高手指点,谢谢!