unit AnimF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Anim;
type
TFormAnimals = class(TForm)
LabelVoice: TLabel;
BtnVoice: TButton;
RbtnAnimal: TRadioButton;
RbtnDog: TRadioButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BtnVoiceClick(Sender: TObject);
procedure RbtnAnimalClick(Sender: TObject);
procedure RbtnDogClick(Sender: TObject);
private
MyAnimal: TAnimal;
end;
var
FormAnimals: TFormAnimals;
implementation
procedure TFormAnimals.FormCreate(Sender: TObject);
begin
MyAnimal := TAnimal.Create;
end;
procedure TFormAnimals.FormDestroy(Sender: TObject);
begin
MyAnimal.Free;
end;
procedure TFormAnimals.BtnVoiceClick(Sender: TObject);
begin
LabelVoice.Caption := MyAnimal.Voice;
end;
procedure TFormAnimals.RbtnAnimalClick(Sender: TObject);
begin
MyAnimal.Free;
MyAnimal := TAnimal.Create;
end;
procedure TFormAnimals.RbtnDogClick(Sender: TObject);
begin
MyAnimal.Free;
MyAnimal := TDog.Create;
end;
end.
|
unit Anim;
interface
type
TAnimal = class
public
constructor Create;
function GetKind: string;
function Voice: string; virtual;
private
Kind: string;
end;
TDog = class (TAnimal)
public
constructor Create;
function Voice: string; override;
end;
implementation
uses
MMSystem;
constructor TAnimal.Create;
begin
Kind := 'An animal';
end;
function TAnimal.GetKind: string;
begin
GetKind := Kind;
end;
function TAnimal.Voice: string;
begin
Voice := 'Voice of the animal';
PlaySound ('Anim.wav', 0, snd_Async);
end;
constructor TDog.Create;
begin
Kind := 'A dog';
end;
function TDog.Voice: string;
begin
Voice := 'Arf Arf';
PlaySound ('dog.wav', 0, snd_Async);
end;
end.
|