unit uWander2; { mk, 23.4.03 }
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
x,y1,y2,dx : integer;
// 1. Referenzvariable vereinbaren
buffer : TBitMap;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
// 3. Puffer verändern
with buffer.Canvas do
begin
// an alter Stelle löschen, dh. mit Hintergrundfarbe zeichnen
Pen.Color := clBtnFace; MoveTo(x,y1); LineTo(x,y2);
// neues x bestimmen
if (x > width-20) or (x // 4. Puffer anzeigen
Canvas.Draw(0,0,buffer);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
x := 10; y1 := 20; y2 := 120; dx := +1;
// 2. BitMap-Objekt erzeugen, Größe setzen
buffer := TBitMap.Create; buffer.Width := Width; buffer.Height := Height;
// 3. in den Puffer zeichnen
with buffer.Canvas do
begin
Pen.width := 20;
Brush.Color := clBtnFace; FillRect(Rect(0,0,width-1,height-1));
MoveTo(x,y1); LineTo(x,y2);
end;
// 4. Puffer anzeigen
Canvas.Draw(0,0,buffer);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// 5. Objekt freigeben
buffer.Free;
end;
end.
|