T
threeone
Unregistered / Unconfirmed
GUEST, unregistred user!
1.关于override
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
ta=class
private
public
function add(s1,s2:integer):integer;virtual;
end;
tb=class(ta)
private
public
function add(s1,s2:integer):integer;override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ta.add(s1,s2:integer):integer;
begin
result:=s1+s2;
end;
function tb.add(s1,s2:integer):integer;
var
a:integer;
begin
inherited add(s1,s2);
a:=3;
result:=result+a;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
//a:ta;
b:tb;
begin
b:=tb.Create;
//a:=ta.Create;
i:=b.add(4,3);
showmessage(inttostr(i));
end;
end.
2.add( /var/ s1,s2:integer) //加var和不加有什么区别???请具例
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
ta=class
private
public
function add(s1,s2:integer):integer;virtual;
end;
tb=class(ta)
private
public
function add(s1,s2:integer):integer;override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ta.add(s1,s2:integer):integer;
begin
result:=s1+s2;
end;
function tb.add(s1,s2:integer):integer;
var
a:integer;
begin
inherited add(s1,s2);
a:=3;
result:=result+a;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
//a:ta;
b:tb;
begin
b:=tb.Create;
//a:=ta.Create;
i:=b.add(4,3);
showmessage(inttostr(i));
end;
end.
2.add( /var/ s1,s2:integer) //加var和不加有什么区别???请具例