Delphi Command mode

Source: Internet
Author: User
Tags rewind


This example is quite understandable, so only the code is provided.
Unit pattern;
Interface
Uses Dialogs;
Type
TAudioPlayer = class;
TCommand = class
Public
Procedure execute; virtual; abstract;
End;
TPlayCommand = class (TCommand)
Private
AudioPlayer: TAudioPlayer;
Public
Procedure execute; override;
Procedure Playcommand (AP: TAudioPlayer );
End;
TStopCommand = class (TCommand)
Private
AudioPlayer: TAudioPlayer;
Public
Procedure execute; override;
Procedure StopComman (AP: TAudioPlayer );
End;
TRewindCommand = class (TCommand)
Private
AudioPlayer: TAudioPlayer;
Public
Procedure execute; override;
Procedure RewindCommand (AP: TAudioPlayer );
End;
TKeyPad = class
Private
PlayCommand: TCommand;
StopCommand: TCommand;
RewindCommand: TCommand;
Public
Constructor Create (PlayC, StopC, RewindC: TCommand); virtual;
Procedure play ();
Procedure stop ();
Procedure rewind ();
End;
TAudioPlayer = class
Public
Procedure play ();
Procedure stop ();
Procedure rewind ();
End;
TClient = class
Private
KeyPad: TKeyPad;
AudioPlayer: TAudioPlayer;
Public
Constructor Create ();
Procedure test ();
End;
Implementation
{TKeyPad}
Constructor TKeyPad. Create (PlayC, StopC, RewindC: TCommand );
Begin
PlayCommand: = PlayC;
StopCommand: = StopC;
RewindCommand: = RewindC;
End;
Procedure TKeyPad. play;
Begin
PlayCommand.exe cute;
End;
Procedure TKeyPad. rewind;
Begin
RewindCommand.exe cute;
End;
Procedure TKeyPad. stop;
Begin
StopCommand.exe cute;
End;
{TAudioPlayer}
Procedure TAudioPlayer. play;
Begin
ShowMessage ('play ');
End;
Procedure TAudioPlayer. rewind;
Begin
ShowMessage ('rewind ');
End;
Procedure TAudioPlayer. stop;
Begin
ShowMessage ('stop ');
End;
{TPlayCommand}
Procedure TPlayCommand.exe cute;
Begin
Inherited;
AudioPlayer. play ();
End;
Procedure TPlayCommand. Playcommand (AP: TAudioPlayer );
Begin
Self. AudioPlayer: = AP;
End;
{TRewindCommand}
Procedure TRewindCommand.exe cute;
Begin
Inherited;
AudioPlayer. Rewind;
End;
Procedure TRewindCommand. RewindCommand (AP: TAudioPlayer );
Begin
AudioPlayer: = ap;
End;
{TStopCommand}
Procedure TStopCommand.exe cute;
Begin
Inherited;
AudioPlayer. Stop;
End;
Procedure TStopCommand. StopComman (AP: TAudioPlayer );
Begin
AudioPlayer: = ap;
End;
{TClient}
Constructor TClient. Create;
Begin
AudioPlayer: = TAudioPlayer. Create ();
End;
Procedure TClient. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.