Einzelnen Beitrag anzeigen

mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.861 Beiträge
 
Delphi 11 Alexandria
 
#16

Re: Timer in Klassen mehrmals verwenden.

  Alt 2. Okt 2006, 17:03
Delphi-Quellcode:
type
  TWindradTimer = class (TTimer)
  private
    FCanvas: TCanvas;
    Fx1: Integer;
  public
    constructor Create (AOwner:TComponent);override;
    constructor Create (AOwner:TComponent; Canvas: TCanvas; startx: Integer);
    procedure setX1( value: Integer);
    procedure OnTimerEvent(Sender:TObject);
  published
    property Canvas: TCanvas read FCanvas write FCanvas;
    property x1: Integer read Fx1 write setX1;
end;
...
constructor TWindradTimer.Create (AOwner:TComponent; Canvas: TCanvas; startx: Integer ) // timer wird erstellt
begin
  inherited Create (AOwner);
  Enabled:=True;
  OnTimer:=OnTimerEvent;
  self.Canvas := Canvas;
  self.x1 := startx;
end;

procedure TWindradTimer.OnTimerEvent(Sender:TObject);
begin
  x1:=x1+1;
  with self.Canvas do begin
    MoveTo(5,5);
    LineTo(x1,5);
  end;
end;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
   x1:=StrToInt(form1.edit1.text);
   y1:=StrToInt(form1.edit2.text);
  Timer1:=TWindradTimer.Create(Form1, Self.Canvas, x1);
end;
Markus Kinzler
  Mit Zitat antworten Zitat