unit u_ampelklasse; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, extCtrls, stdCtrls; type tFarbkreis = class (TShape) private isActive : Boolean; myColor, noColor : TColor; public constructor Create (myOwner : TComponent); override; destructor Destroy (); override; procedure Init (myPos : Array OF Word; myColor : TColor); procedure Toggle (); end; tMyButton = class (TButton) private public constructor Create (myOwner : TComponent); override; destructor Destroy (); override; procedure Init (myPos : Array OF Word; myCaption : String {; myAction : ??? }); end; tf_ampel = class(TForm) private { Private-Deklarationen } fk_gruen, fk_gelb, fk_rot : tFarbkreis; b_wechseln, b_ende : TMyButton; protected public { Public-Deklarationen } constructor Create (myOwner : TComponent); override; destructor Destroy (); override; procedure Init (myPos : Array OF Word); procedure Change (); end; implementation {$R *.DFM} constructor tFarbkreis.Create (myOwner : TComponent); begin inherited Create (myOwner as TComponent); self.parent := (myOwner as TWinControl); end; destructor tFarbkreis.Destroy (); begin inherited Destroy; end; procedure tFarbkreis.Init (myPos : Array OF Word; myColor : TColor); begin self.myColor := myColor; self.noColor := clBlack; self.isActive := false; self.Shape := stCircle; self.Left := myPos[0]; self.Top := myPos[1]; self.Width := 100; self.Height := 100; self.Pen.Color := clBlack; self.Pen.Width := 2; self.Brush.Style := bsSolid; self.Brush.Color := self.noColor; self.Show; end; procedure tFarbkreis.Toggle (); begin end; constructor tMyButton.Create (myOwner : TComponent); begin inherited Create (myOwner as TComponent); self.parent := (myOwner as TWinControl); end; destructor tMyButton.Destroy (); begin inherited Destroy; end; procedure tMyButton.Init (myPos : Array OF Word; myCaption : String {; theAction : ??? }); begin self.Left := myPos[0]; self.Top := myPos[1]; self.Width := 100; self.Height := 25; self.Caption := myCaption; // self.OnClick.Action := self.Parent.name; self.Show; end; constructor tf_ampel.Create (myOwner : TComponent); begin inherited Create (myOwner); self.Parent := Nil; // Desktop ist der Parent; end; destructor tf_ampel.Destroy (); begin self.fk_rot.Destroy; // self.fk_gelb.Destroy; // self.fk_gruen.Destroy; self.b_wechseln.Destroy; // self.b_ende.Destroy; inherited Destroy; end; procedure tf_ampel.Init (myPos : Array OF Word); const rotPos : array[0..1] of Word = (20, 20); gelbPos : array[0..1] of Word = (20,140); gruenPos : array[0..1] of Word = (20,260); wechsPos : array[0..1] of Word = (20,380); endePos : array[0..1] of Word = (20,410); begin self.Left := myPos[0]; self.Top := myPos[1]; self.Height := 495; self.Width := 148; self.Show; // 3 Farbkreise konstruieren und initialisieren: self.fk_rot := tFarbkreis.create (self); self.fk_rot.Init (rotPos, clRed); // gelb und gruen fehlen noch! // 2 Buttons konstruieren und initialisieren: self.b_wechseln := tMyButton.Create (self); self.b_wechseln.Init (wechsPos, 'Ampel schalten'); // self.b_wechseln.OnClick := self.Change (); // Aktion des Buttons fehlt noch! // Ende-Button fehlt noch! end; procedure tf_ampel.Change (); begin end; end.