unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TBike=Class;
TTimer=Class(ExtCtrls.TTimer)
Private
FMyBike:TBike;
public
Property Bike:TBike
read FMyBike;
End;
TBike=Class (TObject)
private
FTimer:TTimer;
FName:
String;
public
Constructor Create(
const aName:
String;aEvent:TNotifyEvent);
overload;
Destructor Destroy;
override;
Property Timer:TTimer
read FTimer;
Property Name:
String Read FName;
end;
TForm3 =
class(TForm)
Button1: TButton;
Timer1: TTimer;
Memo1: TMemo;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
i:Integer;
begin
for I := 1
to 10
do
Listbox1.Items.AddObject(Format('
Bike %d',[i]),TBike.Create(Format('
Bike %d',[i]),Timer1Timer));
end;
{ TBike }
constructor TBike.Create(
const aName:
String;aEvent: TNotifyEvent);
begin
inherited Create;
FTimer := TTimer.Create(
nil);
FTimer.OnTimer := aEvent;
FTimer.Interval := 50;
FTimer.FMyBike := self;
FName := aName;
end;
destructor TBike.Destroy;
begin
FTimer.Free;
end;
procedure TForm3.FormDestroy(Sender: TObject);
var
i:Integer;
begin
for I := Listbox1.Items.Count-1
downto 0
do Listbox1.Items.Objects[i].Free;
Listbox1.Items.Clear;
end;
procedure TForm3.Timer1Timer(Sender: TObject);
begin
if Sender
is TTimer
then
if Assigned(TTimer(Sender).Bike)
then Memo1.Lines.Add(TTimer(Sender).Bike.
Name);
end;
end.