Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 6

Chapter 10 - Project ActivApp

Project Structure

ActivApp.dpr
program ActivApp;

uses
  Forms,
  MainF in 'MainF.pas' {Form1},
  SecondF in 'SecondF.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
MainF.pas
unit MainF;

interface

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

type
  TForm1 = class(TForm)
    LabelApp: TLabel;
    LabelForm: TLabel;
    ApplicationEvents1: TApplicationEvents;
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure AppActivate(Sender: TObject);
    procedure AppDeactivate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
begin
  LabelForm.Caption := 'Form1 Active';
  LabelForm.Color := clRed;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
  LabelForm.Caption := 'Form1 Not Active';
  LabelForm.Color := clBtnFace;
end;

procedure TForm1.AppActivate(Sender: TObject);
begin
  LabelApp.Caption := 'Application Active';
  LabelApp.Color := clRed;
  Beep;
end;

procedure TForm1.AppDeactivate(Sender: TObject);
begin
  LabelApp.Caption := 'Application Not Active';
  LabelApp.Color := clBtnFace;
end;

end.
SecondF.pas
unit SecondF;

interface

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

type
  TForm2 = class(TForm)
    LabelForm: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.FormActivate(Sender: TObject);
begin
  LabelForm.Caption := 'Form2 Active';
  LabelForm.Color := clRed;
end;

procedure TForm2.FormDeactivate(Sender: TObject);
begin
  LabelForm.Caption := 'Form2 Not Active';
  LabelForm.Color := clBtnFace;
end;

end.
MainF.dfm
object Form1: TForm1
  Left = 226
  Top = 137
  Width = 290
  Height = 191
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clBlack
  Font.Height = -19
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  OnActivate = FormActivate
  OnDeactivate = FormDeactivate
  PixelsPerInch = 96
  TextHeight = 24
  object LabelApp: TLabel
    Left = 24
    Top = 24
    Width = 149
    Height = 24
    Caption = 'Application Active'
    Color = clRed
    ParentColor = False
  end
  object LabelForm: TLabel
    Left = 24
    Top = 64
    Width = 91
    Height = 24
    Caption = 'LabelForm'
  end
  object ApplicationEvents1: TApplicationEvents
    OnActivate = AppActivate
    OnDeactivate = AppDeactivate
    Left = 48
    Top = 96
  end
end
SecondF.dfm
object Form2: TForm2
  Left = 76
  Top = 248
  Width = 300
  Height = 193
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clBlack
  Font.Height = -19
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Visible = True
  OnActivate = FormActivate
  OnDeactivate = FormDeactivate
  PixelsPerInch = 96
  TextHeight = 24
  object LabelForm: TLabel
    Left = 24
    Top = 64
    Width = 91
    Height = 24
    Caption = 'LabelForm'
  end
end