unit ListDemoMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Contnrs;
type
TfrmListDemo =
class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
FShapes: TObjectList;
FWait: integer;
procedure CreateShape;
public
{ Public-Deklarationen }
end;
var
frmListDemo: TfrmListDemo;
implementation
{$R *.dfm}
//Dynamisches Erzeugen eines TShape und Ablegen in der Liste
procedure TfrmListDemo.CreateShape;
var Shape: TShape;
begin
Shape := TShape.Create(
nil);
Shape.Parent := self;
Shape.Shape := stCircle;
Shape.Brush.Color := clRed;
Shape.Left := Random(ClientWidth
div Shape.Width) * Shape.Width;
FShapes.Add(Shape);
end;
procedure TfrmListDemo.FormCreate(Sender: TObject);
begin
DoubleBuffered := true;
FShapes := TObjectList.Create;
Randomize;
FWait := 0;
end;
//Freigeben der Liste und aller enthaltenen Objekte
procedure TfrmListDemo.FormDestroy(Sender: TObject);
begin
FShapes.Free;
end;
//ggf. Shape erzeugen oder freigeben, wenn unten angekommen
procedure TfrmListDemo.Timer1Timer(Sender: TObject);
var i: integer;
begin
if FWait
mod 10 = 0
then
CreateShape;
for I := FShapes.Count - 1
downto 0
do
if (FShapes[i]
as TShape).Top >= ClientHeight - (FShapes[i]
as TShape).Height
then
FShapes.Delete(i)
else
(FShapes[i]
as TShape).Top := (FShapes[i]
as TShape).Top + 1;
inc(FWait);
end;
end.