unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Tman=class(Tobject)
public
language:string;
constructor create;virtual;
function sayhello:string;virtual;
procedure hello;virtual;abstract;
end;
Tchinese=class(tman)
public
constructor create;override;
function sayhello:string;override;
end;
Tjapanese=class(Tman)
public
constructor create;override;
function sayhello:string;override;
function sayhello1(p:string):string;overload;
function sayhello1(p:integer):string;overload;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor Tman.create;
begin
language := ‘中文’;
end;
function Tman.sayhello: string;
begin
result:=‘i am a chinese’;
end;
{ Tchinese }
constructor Tchinese.create;
begin
//inherited;
language := ‘chinese’;
end;
function Tchinese.sayhello: string;
begin
result:=‘我是一個中國人’;
end;
{ Tjapanese }
constructor Tjapanese.create;
begin
//inherited;
language := ‘japanese’;
end;
function Tjapanese.sayhello: string;
begin
result:=‘我是一個日本仔’;
end;
function Tjapanese.sayhello1(p:string):string;
begin
if p='2’then
result:=‘123’;
end;
function Tjapanese.sayhello1(p:integer):string;
begin
if p=2 then
result:=‘123456789’;
end;
procedure TForm1.Button1Click(Sender: TObject);
var aman:Tman;
begin
aman := Tchinese.create;//parent:=child;
edit1.Text := aman.language;
showmessage(aman.sayhello);
end;
procedure TForm1.Button2Click(Sender: TObject);
var aman:Tjapanese;
begin
aman := Tjapanese.create;
edit1.Text := aman.language;
showmessage(aman.sayhello);
showmessage(aman.sayhello1(2));
end;
end.