unit Monster6;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TMonster = class
  private
    Name: String;
  public
    procedure Erscheinen (BildName: String);
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Panel1: TPanel;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const Pfad = '.\bilder\';   // 'c:\delphi\buch\bilder\';
var
  Form1: TForm1;
  WerWohl: TMonster;
  Zufall : Integer;

implementation

{$R *.DFM}

procedure TMonster.Erscheinen (BildName: String);
begin
  Form1.Image1.Picture.LoadFromFile (Pfad+BildName);
  Name := Copy (BildName,1,Length(BildName)-4);
  Form1.Panel1.Caption := Name;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Zufall := random(5);
  case Zufall of
    0: WerWohl.Erscheinen ('Frank.bmp');
    1: WerWohl.Erscheinen ('Albert.bmp');
    2: WerWohl.Erscheinen ('Sigmund.bmp');
    3: WerWohl.Erscheinen ('Jekyll.bmp');
    4: WerWohl.Erscheinen ('Hyde.bmp');
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;
  WerWohl := TMonster.Create;
  Timer1.Enabled := false;
  Timer1.Interval := 500;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Timer1.Enabled then // = Start
  begin
    Timer1.Enabled := true;
    Button1.Caption := 'Stop';
    Image1.Show;
  end
  else  // = Stop
  begin
    Timer1.Enabled := false;
    Button1.Caption := 'Start';
    Panel1.Caption := '';
    Image1.Hide;
  end;
end;

end.
