![]() |
||
| Material |
OOP
Grundlagen
Delphi
Software-Technik
Bonsai
Digitaltechnik
Ereignisse
Grafik
UML
Netze
Fischertechnik
Tipps
Werkzeuge
Literatur
Automaten
Sprachen
Datenbanken
XML
Prolog
Berechenbarkeit
|
|
|
Beispiele für Dokumentationen |
![]() |
Die Ampel (besser: die Ansicht der Ampel) besteht aus zwei Panels und
3 Shapes. Mit shRot.Brush.Color := clRed läßt sich die Farbe einstellen. Die Farbe wird nach einer Änderung sofort aktualisiert |
erstellt mit Dia![]() |
![]() |
| mit Polling | mit Ereignis |
erstellt mit
StruktEd
UNIT mTAmpel1;
interface
type
TZustand = (rot,rotgelb,gruen,gelb);
TAmpel = CLASS
// Attribute
private
FZustand : TZustand;
// Methoden
public
procedure SetZustand(z : TZustand);
procedure switchZustand;
function GetZustand : TZustand;
constructor Create;
end;
implementation
//+---------------------------------------------------------------------
//| TAmpel: Methodendefinition
//+---------------------------------------------------------------------
constructor TAmpel.Create;
begin
inherited Create;
FZustand := rot;
end;
//-------- SetZustand (public) -----------------------------------------
procedure TAmpel.SetZustand(z : TZustand);
begin
FZustand := z;
end;
//-------- switchZustand (public) --------------------------------------
procedure TAmpel.switchZustand;
begin
case FZustand of
rot : FZustand := rotgelb;
rotgelb : FZustand := gruen;
gruen : FZustand := gelb;
gelb : FZustand := rot;
end;
end;
//-------- GetZustand (public) -----------------------------------------
function TAmpel.GetZustand : TZustand;
begin
Result := FZustand;
end;
end.
|
UNIT mTAmpel5; { mk, 9.5.03, Fußgängerampel 1}
interface
type
TZustand = (rot,rotgelb,dauergruen,gruen,gelb);
TEingabe = (OCN,Taste);
TEreignis = procedure of object;
TAmpel = CLASS
// Attribute
private
FZustand : TZustand;
FCounter : word;
public
OnChangeZustand : TEreignis;
// Methoden
public
procedure SetZustand(z : TZustand);
procedure switchZustand(eingabe : TEingabe);
function GetZustand : TZustand;
constructor Create;
procedure SetCounter(t : word);
function GetCounter : word;
procedure DecCounter;
end;
implementation
//+---------------------------------------------------------------------
//| TAmpel: Methodendefinition
//+---------------------------------------------------------------------
constructor TAmpel.Create;
begin
inherited Create;
FZustand := dauergruen; FCounter := 0;
if Assigned(OnChangeZustand) then OnChangeZustand;
end;
//-------- SetZustand (public) -----------------------------------------
procedure TAmpel.SetZustand(z : TZustand);
begin
FZustand := z;
if Assigned(OnChangeZustand) then OnChangeZustand;
end;
//-------- switchZustand (public) --------------------------------------
procedure TAmpel.switchZustand(eingabe : TEingabe);
begin
if eingabe = OCN
then
case FZustand of
rot : begin FZustand := rotgelb; setCounter(2); end;
rotgelb : begin FZustand := gruen; setCounter(10); end;
gruen : begin FZustand := dauergruen; setCounter(0); end;
dauergruen : { leer } ;
gelb : begin FZustand := rot; setCounter(10); end;
end
else { eingabe = Taste }
case FZustand of
rot : { leer } ;
rotgelb : { leer } ;
gruen : { leer } ;
dauergruen : begin FZustand := gelb; setCounter(2); end;
gelb : { leer } ;
end;
if Assigned(OnChangeZustand) then OnChangeZustand;
end;
//-------- GetZustand (public) -----------------------------------------
function TAmpel.GetZustand : TZustand;
begin
Result := FZustand;
end;
procedure TAmpel.SetCounter(t : word);
begin
FCounter := t;
end;
procedure TAmpel.DecCounter;
begin
if FCounter > 0
then
begin
FCounter := FCounter - 1;
if FCounter = 0 then switchZustand(OCN);
end;
end;
function TAmpel.GetCounter : word ;
begin
Result := FCounter;
end;
end.
|
unit uAmpel5GUI; { mk, 11.5.03 , Fußgängerampel 1 }
{$DEFINE DEBUG}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, mTAmpel5;
type
TGUI = class(TForm)
pAmpel: TPanel; shRot: TShape; shGelb: TShape; shGruen: TShape;
pStange: TPanel; Timer1: TTimer;
bTaste: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure bTasteClick(Sender: TObject);
private
{$IFDEF DEBUG}
lCounter, lZustand : TLabel;
{$ENDIF}
Ampel : TAmpel;
procedure updateView;
public
{ Public-Deklarationen }
end;
var
GUI: TGUI;
implementation
{$R *.DFM}
procedure TGUI.FormCreate(Sender: TObject);
begin
Ampel := TAmpel.Create;
Ampel.OnChangeZustand := updateView;
updateView;
{$IFDEF DEBUG}
lCounter := TLabel.Create(self); // hier: self = GUI
lCounter.Parent := self; lCounter.top := 380; lCounter.Left := 90;
lCounter.caption := '0';
lZustand := TLabel.Create(self);
lZustand.Parent := self; lZustand.top := 400; lZustand.Left := 90;
lZustand.caption := 'dauergruen';
{$ENDIF}
end;
.......
procedure TGUI.updateView;
const
clGreen = $0000FF00; // Hilfe zu TColor
begin
case Ampel.GetZustand of
rot : begin
shRot.Brush.Color := clRed;
shGelb.Brush.Color := clBlack;
shGruen.Brush.Color := clBlack;
{$IFDEF DEBUG} lZustand.caption := 'rot'; {$ENDIF}
end;
rotgelb : begin
shRot.Brush.Color := clRed;
shGelb.Brush.Color := clYellow;
shGruen.Brush.Color := clBlack;
{$IFDEF DEBUG} lZustand.caption := 'rotgelb'; {$ENDIF}
end;
dauergruen : begin
shRot.Brush.Color := clBlack;
shGelb.Brush.Color := clBlack;
shGruen.Brush.Color := clGreen;
{$IFDEF DEBUG} lZustand.caption := 'dauergruen'; {$ENDIF}
end;
gruen : begin
shRot.Brush.Color := clBlack;
shGelb.Brush.Color := clBlack;
shGruen.Brush.Color := clGreen;
{$IFDEF DEBUG} lZustand.caption := 'gruen'; {$ENDIF}
end;
gelb : begin
shRot.Brush.Color := clBlack;
shGelb.Brush.Color := clYellow;
shGruen.Brush.Color := clBlack;
{$IFDEF DEBUG} lZustand.caption := 'gelb'; {$ENDIF}
end;
end;
end;
procedure TGUI.Timer1Timer(Sender: TObject);
begin
Ampel.DecCounter;
{$IFDEF DEBUG} lCounter.caption := IntToStr(Ampel.GetCounter); {$ENDIF}
end;
.........
end.
|
