Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco



Home: Code Repository: Mastering Delphi 5

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