手机
当前位置:查字典教程网 >编程开发 >Delphi >Delphi Command模式
Delphi Command模式
摘要:这个例子还是比较好理解的,所以只给出代码.unitpattern;interfaceusesDialogs;typeTAudioPlayer...

这个例子还是比较好理解的,所以只给出代码.

unitpattern;

interface

usesDialogs;

type

TAudioPlayer=class;

TCommand=class

public

procedureexecute;virtual;abstract;

end;

TPlayCommand=class(TCommand)

private

AudioPlayer:TAudioPlayer;

public

procedureexecute;override;

procedurePlaycommand(AP:TAudioPlayer);

end;

TStopCommand=class(TCommand)

private

AudioPlayer:TAudioPlayer;

public

procedureexecute;override;

procedureStopComman(AP:TAudioPlayer);

end;

TRewindCommand=class(TCommand)

private

AudioPlayer:TAudioPlayer;

public

procedureexecute;override;

procedureRewindCommand(AP:TAudioPlayer);

end;

TKeyPad=class

private

PlayCommand:TCommand;

StopCommand:TCommand;

RewindCommand:TCommand;

public

constructorCreate(PlayC,StopC,RewindC:TCommand);virtual;

procedureplay();

procedurestop();

procedurerewind();

end;

TAudioPlayer=class

public

procedureplay();

procedurestop();

procedurerewind();

end;

TClient=class

private

KeyPad:TKeyPad;

AudioPlayer:TAudioPlayer;

public

constructorCreate();

proceduretest();

end;

implementation

{TKeyPad}

constructorTKeyPad.Create(PlayC,StopC,RewindC:TCommand);

begin

PlayCommand:=PlayC;

StopCommand:=StopC;

RewindCommand:=RewindC;

end;

procedureTKeyPad.play;

begin

PlayCommand.execute;

end;

procedureTKeyPad.rewind;

begin

RewindCommand.execute;

end;

procedureTKeyPad.stop;

begin

StopCommand.execute;

end;

{TAudioPlayer}

procedureTAudioPlayer.play;

begin

ShowMessage(´play´);

end;

procedureTAudioPlayer.rewind;

begin

ShowMessage(´rewind´);

end;

procedureTAudioPlayer.stop;

begin

ShowMessage(´stop´);

end;

{TPlayCommand}

procedureTPlayCommand.execute;

begin

inherited;

AudioPlayer.play();

end;

procedureTPlayCommand.Playcommand(AP:TAudioPlayer);

begin

self.AudioPlayer:=AP;

end;

{TRewindCommand}

procedureTRewindCommand.execute;

begin

inherited;

AudioPlayer.Rewind;

end;

procedureTRewindCommand.RewindCommand(AP:TAudioPlayer);

begin

AudioPlayer:=ap;

end;

{TStopCommand}

procedureTStopCommand.execute;

begin

inherited;

AudioPlayer.Stop;

end;

procedureTStopCommand.StopComman(AP:TAudioPlayer);

begin

AudioPlayer:=ap;

end;

{TClient}

constructorTClient.Create;

begin

AudioPlayer:=TAudioPlayer.Create();

end;

procedureTClient.test;

var

PlayCommand:TCommand;

StopCommand:TCommand;

RewindCommand:TCommand;

begin

PlayCommand:=TPlayCommand.Create;

StopCommand:=TStopCommand.Create;

RewindCommand:=TRewindCommand.Create;

KeyPad:=TKeyPad.Create(PlayCommand,StopCommand,RewindCommand);

KeyPad.stop;

KeyPad.play;

KeyPad.rewind;

KeyPad.Stop;

end;

end.

【Delphi Command模式】相关文章:

delphi简单判断程序30秒没有键盘和鼠标动作示例

delphi mysql adbquery数据提供程序或其他服务返回 E_FAIL 状态

delphi发送消息控制滚动条使用示例

Delphi基本图像处理方法汇总

截取指定符号之间的字符串(随机读取)delphi实例代码

delphi中一个值得大家来考虑的DLL问题

Delphi7中群发Email邮件的方法

Delphi之Pascal语言中的关键字及保留字汇总

Delphi控件ListView的属性及使用方法详解

Delphi实例演示Rect、Bounds生成TRect的区别

精品推荐
分类导航