Nach Entfernung von Globalreferenzen:
Delphi-Quellcode:
type
TWindradTimer = class (TTimer)
private
FCanvas: TCanvas;
public
constructor Create (AOwner:TComponent);override;
constructor Create (AOwner:TComponent; Canvas: TCanvas);
procedure OnTimerEvent(Sender:TObject);
published
property Canvas: TCanvas read FCanvas write FCanvas;
end;
...
constructor TWindradTimer.Create (AOwner:TComponent; Canvas: TCanvas; ) // timer wird erstellt
begin
inherited Create (AOwner);
Enabled:=True;
OnTimer:=OnTimerEvent;
self.Canvas ;= Canvas;
end;
procedure TWindradTimer.OnTimerEvent(Sender:TObject);
begin
x2:=x2+1;
with self.Canvas do begin
MoveTo(5,5);
LineTo(x2,5);
end;
end;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1:=TWindradTimer.Create(Form1, Self.Canvas);
end;