unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls,
  Unit2;


type
  TMainForm = class(TForm)
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    btnSTART: TBitBtn;
    btnCloseWindows: TBitBtn;
    procedure btnCloseWindowsClick(Sender: TObject);
    procedure btnSTARTClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);

  private
    nr_okna : Integer;

  public

  end;

var
  MainForm: TMainForm;

implementation
{$R *.dfm}
{------------------------------------------------------------------------------}
procedure TMainForm.BitBtn1Click(Sender: TObject);
begin
	Close();
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
   nr_okna := 0;
   Randomize();
end;

procedure TMainForm.btnSTARTClick(Sender: TObject);
var
   lp          : Integer;
	wsk_na_okno : TForm2;
	x           : Integer;
   y           : Integer;

begin
	for lp := 1 to 10 do
	begin
   	Inc(nr_okna);
	   wsk_na_okno := TForm2.Create(Application, nr_okna);
      wsk_na_okno.Parent := Self;
		wsk_na_okno.Show();

	   x := random(800);
   	y := random(600);

	   wsk_na_okno.Left := x;
	   wsk_na_okno.Top  := y;
   end;
end;

procedure TMainForm.btnCloseWindowsClick(Sender: TObject);
var
   lp          : Integer;
   wsk         : TComponent;

begin
	lp := 0;
   for lp := 0 to Application.ComponentCount-1 do
   begin
      wsk := Application.Components[lp];
      if (wsk is TForm2) then
      begin
         (wsk as TForm2).Close();
      end;
   end;
end;

end.

