Marco Cantù 1998, Mastering Delphi 4

Project: CHILD.DPR


Project Structure


CHILD.DPR

program Child;

uses
  Forms,
  MainF in 'MainF.pas' {MainForm},
  ChildF in 'ChildF.pas' {ChildForm};

{$R *.RES}

begin
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.

MAINF.PAS

unit MainF;

interface

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

type
  TMainForm = class(TForm)
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
    Counter: Integer;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.FormClick(Sender: TObject);
var
  NewForm: TChildForm;
begin
  // increase the child window counter
  Inc (Counter);
  {create a new form and define it as child
  of the current form}
  NewForm:= TChildForm.Create (self);
  NewForm.Parent := self;
  // add the number to the caption, and move it slightly
  NewForm.Caption := NewForm.Caption + ' ' + IntToStr (Counter);
  NewForm.Left := (Counter * 20) mod 500;
  NewForm.Top := (Counter * 20) mod 450;
  // show the form
  NewForm.Show;
end;

end.

CHILDF.PAS

unit ChildF;

interface

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

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

var
  ChildForm: TChildForm;

implementation

{$R *.DFM}

end.

MAINF.DFM

object MainForm: TMainForm
  Left = 286
  Top = 221
  Width = 435
  Height = 300
  Caption = 'Main Form'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  OldCreateOrder = True
  OnClick = FormClick
  PixelsPerInch = 96
  TextHeight = 16
end

CHILDF.DFM

object ChildForm: TChildForm
  Left = 71
  Top = 95
  Width = 200
  Height = 116
  Caption = 'Child Form'
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
end


Copyright Marco Cantù 1998