H
hsgrass
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Ttest1 = class(Tobject)
function IsOk: boolean
virtual;
procedure a()
virtual;
end;
Ttest2 = class(Ttest1)
function IsOk: boolean;
procedure a()
override;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
t2, t22: ttest2;
t1: ttest1;
begin
t1 := ttest1.Create;
ttest2(t1).a
// 怎样使t1执行ttest2.a过程,而不是test1.a??
t1.free;
end;
{ Ttest1 }
procedure Ttest1.a;
begin
if not IsOk then
ShowMessage('do right!!');
end;
function Ttest1.IsOk: boolean;
begin
result := true;
end;
{ Ttest2 }
procedure Ttest2.a;
begin
if not IsOk then
showmessage('test2 ok ');
end;
function Ttest2.IsOk: boolean;
begin
result := false;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Ttest1 = class(Tobject)
function IsOk: boolean
virtual;
procedure a()
virtual;
end;
Ttest2 = class(Ttest1)
function IsOk: boolean;
procedure a()
override;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
t2, t22: ttest2;
t1: ttest1;
begin
t1 := ttest1.Create;
ttest2(t1).a
// 怎样使t1执行ttest2.a过程,而不是test1.a??
t1.free;
end;
{ Ttest1 }
procedure Ttest1.a;
begin
if not IsOk then
ShowMessage('do right!!');
end;
function Ttest1.IsOk: boolean;
begin
result := true;
end;
{ Ttest2 }
procedure Ttest2.a;
begin
if not IsOk then
showmessage('test2 ok ');
end;
function Ttest2.IsOk: boolean;
begin
result := false;
end;
end.