Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 5

Project MULTIWIN

Project Structure


MULTIWIN.DPR

program MultiWin;

uses
  Forms,
  MainForm in 'MainForm.pas' {Form1},
  MWForm2 in 'MWForm2.pas' {Form2},
  MWForm3 in 'MWForm3.pas' {Form3},
  MWForm4 in 'MWForm4.pas' {Form4};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm4, Form4);
  Application.Run;
end.

MAINFORM.PAS

unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    btnMultiple: TButton;
    btnSingle: TButton;
    btnModal: TButton;
    procedure btnSingleClick(Sender: TObject);
    procedure btnMultipleClick(Sender: TObject);
    procedure btnModalClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  MWForm2, MWForm3, MWForm4;

{$R *.DFM}

procedure TForm1.btnSingleClick(Sender: TObject);
begin
  if not Assigned (Form2) then
    Form2 := TForm2.Create (Application);
  Form2.Show;
end;

procedure TForm1.btnMultipleClick(Sender: TObject);
begin
  with TForm3.Create (Application) do
    Show;
end;

procedure TForm1.btnModalClick(Sender: TObject);
var
  Modal: TForm4;
begin
  Modal := TForm4.Create (Application);
  try
    Modal.ShowModal;
  finally
    Modal.Free;
  end;
end;

end.

MWFORM2.PAS

unit MWForm2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  // important: set pointer to nil!
  Form2 := nil;
end;

end.

MWFORM3.PAS

unit MWForm3;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm3 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

// removed for extra safety
{var
  Form3: TForm3;}

implementation

{$R *.DFM}

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

end.

MWFORM4.PAS

unit MWForm4;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm4 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

{$R *.DFM}

end.

MAINFORM.DFM

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 167
  Height = 181
  Caption = 'MultiWin'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnMultiple: TButton
    Left = 40
    Top = 16
    Width = 75
    Height = 25
    Caption = 'Multiple'
    TabOrder = 0
    OnClick = btnMultipleClick
  end
  object btnSingle: TButton
    Left = 40
    Top = 96
    Width = 75
    Height = 25
    Caption = 'Single'
    TabOrder = 1
    OnClick = btnSingleClick
  end
  object btnModal: TButton
    Left = 40
    Top = 56
    Width = 75
    Height = 25
    Caption = 'Modal'
    TabOrder = 2
    OnClick = btnModalClick
  end
end

MWFORM2.DFM

object Form2: TForm2
  Left = 389
  Top = 105
  Width = 291
  Height = 180
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
end

MWFORM3.DFM

object Form3: TForm3
  Left = 209
  Top = 259
  Width = 290
  Height = 180
  Caption = 'Form3'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDefaultPosOnly
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
end

MWFORM4.DFM

object Form4: TForm4
  Left = 342
  Top = 344
  Width = 279
  Height = 203
  Caption = 'Form4'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
end