C
coolrain
Unregistered / Unconfirmed
GUEST, unregistred user!
这virtual是怎么回事??
以下是Delphi help 中的例子,可要我的delphi中编绎不能通过:
unit Unit1;
interface
uses
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;
type
TFigure = class
procedure Draw
virtual;
end;
TRectangle = class(TFigure)
procedure Draw
override;
end;
TEllipse = class(TFigure)
procedure Draw
override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TRectangle }
procedure TRectangle.Draw;
begin
inherited;
end;
{ TEllipse }
procedure TEllipse.Draw;
begin
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Figure: TFigure;
begin
Figure := TRectangle.Create;
Figure.Draw
// calls TRectangle.Draw
Figure.Destroy;
Figure := TEllipse.Create;
Figure.Draw
// calls TEllipse.Draw
Figure.Destroy;
end;
end.
{ TEllipse }
procedure TEllipse.Draw;
begin
inherited;
end;
end.
以下是Delphi help 中的例子,可要我的delphi中编绎不能通过:
unit Unit1;
interface
uses
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;
type
TFigure = class
procedure Draw
virtual;
end;
TRectangle = class(TFigure)
procedure Draw
override;
end;
TEllipse = class(TFigure)
procedure Draw
override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TRectangle }
procedure TRectangle.Draw;
begin
inherited;
end;
{ TEllipse }
procedure TEllipse.Draw;
begin
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Figure: TFigure;
begin
Figure := TRectangle.Create;
Figure.Draw
// calls TRectangle.Draw
Figure.Destroy;
Figure := TEllipse.Create;
Figure.Draw
// calls TEllipse.Draw
Figure.Destroy;
end;
end.
{ TEllipse }
procedure TEllipse.Draw;
begin
inherited;
end;
end.