unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Menus;

type
  TMainForm = class(TForm)
    MainMenu1: TMainMenu;
    Akcja1: TMenuItem;
    Pokaokno1: TMenuItem;
    Koniecpracy1: TMenuItem;
    StatusBar1: TStatusBar;
    procedure Pokaokno1Click(Sender: TObject);
    procedure Koniecpracy1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses UOkno;
{$R *.dfm}

procedure TMainForm.Koniecpracy1Click(Sender: TObject);
begin
	if Application.MessageBox('Koniec pracy?', 'Uwaga', MB_YESNO or MB_ICONQUESTION) = mrYes then
	begin
		Close();
   end;
end;

procedure TMainForm.Pokaokno1Click(Sender: TObject);
var
	rezultat : TModalResult;

begin
	// tutaj pamiętamy rezultat
   rezultat := mrNone;

	// jezeli okno jeszcze nie istnieje
	if not Assigned(Form2) then
   begin
      try
      	// utwórz okno
		   Form2 := TForm2.Create(Application);
         // pokaż go modalnie
         rezultat := Form2.ShowModal();

			if rezultat = mrOk then
      	begin
      		ShowMessage('Okno zamknięte przyciskiem OK');
      	end;

			if rezultat = mrCancel then
      	begin
      		ShowMessage('Okno zamkniete przyciskiem Anuluj');
         end;
		finally
 			FreeAndNil(Form2);
      end;
   end;
end;

end.
