1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
TPanneau = class(TPanel)
private
NextFree: TPanneau;
public
Index: Integer;
Nom: String;
procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
end;
{ TForm1 }
TForm1 = class(TForm)
procedure FormClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FreeList:TPanneau;
procedure AppIdle(Sender: TObject; var Done: Boolean);
public
Panneau: array[1..3] of TPanneau;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormClick(Sender: TObject);
var
i, j: Integer;
begin
j:= 0;
for i:= 1 to 3 do
// if Panneau[i] = nil then
if not Assigned(Panneau[i]) then
begin
j:= i;
Break;
end;
if (j < 1) or (j > 3) then
ShowMessage('Indice hors limite j = '+ IntToStr(j))
else
begin
Panneau[j]:= TPanneau.Create(Self);
with Panneau[j] do
begin
Parent:= TWinControl(Self);
index := J;
Caption:= IntToStr(j);
SetBounds(100, 60*i, 200, 30);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnIdle := @AppIdle;
end;
procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
var
t,n:TPanneau;
begin
t:= FreeList;
FreeList := nil;
while t <> nil do
begin
n := t.NextFree;
t.Free;
t:= n;
end;
end;
procedure TPanneau.MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer);
begin
TForm1(Parent).Panneau[Index] := nil;
NextFree := TForm1(Parent).FreeList;
TForm1(Parent).FreeList := Self;
end;
end. |
Partager