unit DemoFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TDemoForm =
class(TForm)
ListBox: TListBox;
InfoButton: TButton;
procedure InfoButtonClick(Sender: TObject);
procedure PanelClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FreeList: TList;
procedure AppIdle(Sender: TObject;
var done: boolean);
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
procedure TDemoForm.AppIdle(Sender: TObject;
var done: boolean);
begin
// free objects one by one
with FreeList
do
if Count > 0
then
TObject(Extract(First)).Free;
end;
procedure TDemoForm.InfoButtonClick(Sender: TObject);
begin
with TPanel.Create(self)
do
begin
Parent := self;
// make visible
Left := ListBox.Left + 10;
Top := ListBox.Top + 10;
// ...
OnClick := PanelClick;
end;
end;
procedure TDemoForm.PanelClick(Sender: TObject);
begin
with Sender
as TPanel
do
if Caption = '
'
then Caption := DateTimeToStr(now)
else FreeList.Add(Sender);
end;
procedure TDemoForm.FormCreate(Sender: TObject);
begin
FreeList := TList.Create;
Application.OnIdle := AppIdle;
end;
procedure TDemoForm.FormDestroy(Sender: TObject);
begin
FreeList.Free;
end;
end.