B
billy_yuan
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TGo = class(TObject)
Name:String ;
procedure goBefore ;
virtual ;
procedure going ;
virtual ;
procedure goAfter ;virtual ;
function go():String ;
end ;
TGoSchool =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;
override ;
procedure going ;
override ;
end ;
TGoMarket =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;override ;
procedure going ;
override ;
end ;
TGoOffice =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;override ;
procedure going ;override ;
end ;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TGo.go: String;
begin
gobefore ;
going ;
goafter ;
end;
procedure TGo.goAfter;
begin
end;
procedure TGo.goBefore;
begin
end;
procedure TGo.going;
begin
end;
procedure TGoSchool.goAfter;
begin
Application.MessageBox('我到了学校,开始上课!!',pchar(self.name),0) ;
end;
procedure TGoSchool.goBefore;
begin
Application.MessageBox('我要记得带作业!',pchar(self.name),0) ;
end;
procedure TGoSchool.going;
begin
Application.MessageBox('路上的MM可真多啊,要是爸爸在就好了!',pchar(self.name),0) ;
end;
procedure TGoMarket.goAfter;
begin
Application.MessageBox('今天买的东西可就真多啊,真重!',pchar(self.name),0) ;
end;
procedure TGoMarket.goBefore;
begin
Application.MessageBox('今天记得要买什么东西?对了,今天要去家乐福',pchar(self.name),0) ;
end;
procedure TGoMarket.going;
begin
Application.MessageBox('车上真挤,那个臭男人怎么老是盯着我看!',pchar(self.name),0) ;
end;
procedure TgoOffice.goAfter;
begin
Application.MessageBox('到公司了,开始上班!',pchar(self.name),0) ;
end;
procedure TgoOffice.goBefore;
begin
Application.MessageBox('小丽正等着我呢!',pchar(self.name),0) ;//小丽乃秘书也
end;
procedure TgoOffice.going;
begin
Application.MessageBox('路上的MM可真多啊,要是儿子在就好了!',pchar(self.name),0) ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
son:TGoSchool ;
mother:TGoMarket ;
dady:TGoOffice ;
family:TStringlist ;
i:integer ;
begin
son := TGoSchool.Create ;
son.Name := '儿子' ;
mother := TGoMarket.Create ;
mother.Name := '妈妈';
dady := TGoOffice.Create ;
dady.Name := '爸爸';
family := TStringlist.Create ;
family.AddObject('1',son) ;
family.AddObject('2',mother) ;
family.AddObject('3',dady) ;
for i:=0 to family.Count-1do
begin
TGo(family.Objects).go ;
end ;
end;
end.
这是我自己编写的一个例子。
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TGo = class(TObject)
Name:String ;
procedure goBefore ;
virtual ;
procedure going ;
virtual ;
procedure goAfter ;virtual ;
function go():String ;
end ;
TGoSchool =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;
override ;
procedure going ;
override ;
end ;
TGoMarket =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;override ;
procedure going ;
override ;
end ;
TGoOffice =class(TGo)
procedure goBefore ;override ;
procedure goAfter ;override ;
procedure going ;override ;
end ;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TGo.go: String;
begin
gobefore ;
going ;
goafter ;
end;
procedure TGo.goAfter;
begin
end;
procedure TGo.goBefore;
begin
end;
procedure TGo.going;
begin
end;
procedure TGoSchool.goAfter;
begin
Application.MessageBox('我到了学校,开始上课!!',pchar(self.name),0) ;
end;
procedure TGoSchool.goBefore;
begin
Application.MessageBox('我要记得带作业!',pchar(self.name),0) ;
end;
procedure TGoSchool.going;
begin
Application.MessageBox('路上的MM可真多啊,要是爸爸在就好了!',pchar(self.name),0) ;
end;
procedure TGoMarket.goAfter;
begin
Application.MessageBox('今天买的东西可就真多啊,真重!',pchar(self.name),0) ;
end;
procedure TGoMarket.goBefore;
begin
Application.MessageBox('今天记得要买什么东西?对了,今天要去家乐福',pchar(self.name),0) ;
end;
procedure TGoMarket.going;
begin
Application.MessageBox('车上真挤,那个臭男人怎么老是盯着我看!',pchar(self.name),0) ;
end;
procedure TgoOffice.goAfter;
begin
Application.MessageBox('到公司了,开始上班!',pchar(self.name),0) ;
end;
procedure TgoOffice.goBefore;
begin
Application.MessageBox('小丽正等着我呢!',pchar(self.name),0) ;//小丽乃秘书也
end;
procedure TgoOffice.going;
begin
Application.MessageBox('路上的MM可真多啊,要是儿子在就好了!',pchar(self.name),0) ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
son:TGoSchool ;
mother:TGoMarket ;
dady:TGoOffice ;
family:TStringlist ;
i:integer ;
begin
son := TGoSchool.Create ;
son.Name := '儿子' ;
mother := TGoMarket.Create ;
mother.Name := '妈妈';
dady := TGoOffice.Create ;
dady.Name := '爸爸';
family := TStringlist.Create ;
family.AddObject('1',son) ;
family.AddObject('2',mother) ;
family.AddObject('3',dady) ;
for i:=0 to family.Count-1do
begin
TGo(family.Objects).go ;
end ;
end;
end.
这是我自己编写的一个例子。