Marco Cantù 1998, Mastering Delphi 4

Project: STATUSB.DPR


Project Structure


STATUSB.DPR

program Statusb;

uses
  Forms,
  StatusF in 'StatusF.pas' {Form1};

{$R *.RES}

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

STATUSF.PAS

unit StatusF;

interface

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

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    New1: TMenuItem;
    Open1: TMenuItem;
    Save1: TMenuItem;
    Saveas1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Help1: TMenuItem;
    About1: TMenuItem;
    Edit1: TMenuItem;
    Undo1: TMenuItem;
    N2: TMenuItem;
    Cut1: TMenuItem;
    Copy1: TMenuItem;
    Paste1: TMenuItem;
    StatusBar1: TStatusBar;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowHint(Sender: TObject);
    procedure CheckCapslock;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnHint := ShowHint;
end;

procedure TForm1.ShowHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;

procedure TForm1.CheckCapslock;
begin
  if Odd (GetKeyState (VK_CAPITAL)) then
    StatusBar1.Panels[1].Text := 'CAPS'
  else
    StatusBar1.Panels[1].Text := '';
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  CheckCapslock;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  CheckCapslock;
end;

end.

STATUSF.DFM

object Form1: TForm1
  Left = 233
  Top = 162
  Width = 435
  Height = 300
  Caption = 'Status Bar'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu1
  OnCreate = FormCreate
  OnKeyDown = FormKeyDown
  PixelsPerInch = 96
  TextHeight = 13
  object StatusBar1: TStatusBar
    Left = 0
    Top = 235
    Width = 427
    Height = 19
    Panels = <
      item
        Width = 300
      end
      item
        Alignment = taCenter
        Width = 50
      end
      item
        Width = 100
      end>
    SimplePanel = False
  end
  object MainMenu1: TMainMenu
    Left = 32
    Top = 8
    object File1: TMenuItem
      Caption = '&File'
      Hint = 'Operations on files'
      object New1: TMenuItem
        Caption = '&New...'
        Hint = 'Create a new file'
      end
      object Open1: TMenuItem
        Caption = '&Open...'
        Hint = 'Open an existing file'
      end
      object Save1: TMenuItem
        Caption = '&Save'
        Hint = 'Save the current file'
      end
      object Saveas1: TMenuItem
        Caption = 'Save &as...'
        Hint = 'Save the current file with a new name'
      end
      object N1: TMenuItem
        Caption = '-'
      end
      object Exit1: TMenuItem
        Caption = 'E&xit'
        Hint = 'Terminate the application'
      end
    end
    object Edit1: TMenuItem
      Caption = '&Edit'
      Hint = 'Operations on the text'
      object Undo1: TMenuItem
        Caption = '&Undo'
        Hint = 'Reverse the last action'
      end
      object N2: TMenuItem
        Caption = '-'
      end
      object Cut1: TMenuItem
        Caption = 'Cu&t'
        Hint = 'Delete the selection, moving it to the clipboard'
      end
      object Copy1: TMenuItem
        Caption = '&Copy'
        Hint = 'Make a copy of the current selection to the clipboard'
      end
      object Paste1: TMenuItem
        Caption = '&Paste'
        Hint = 'Paste the current clipboard data'
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      Hint = 'Access information about the program'
      object About1: TMenuItem
        Caption = 'About...'
        Hint = 'Display the About Box'
      end
    end
  end
  object Timer1: TTimer
    OnTimer = Timer1Timer
    Left = 80
    Top = 8
  end
end


Copyright Marco Cantù 1998