Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 5

Project NEWCHECK

Project Structure


NEWCHECK.DPR

program Newcheck;

uses
  Forms,
  CHECK in 'CHECK.PAS' {Form1};

{$R *.RES}

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

CHECK.PAS

unit Check;

interface

uses Windows, Classes, Graphics, Forms, Controls, Menus,
  StdCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Command1: TMenuItem;
    Toggle1: TMenuItem;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Toggle1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    Bmp1, Bmp2: TBitmap;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Bmp1 := TBitmap.Create;
  Bmp2 := TBitmap.Create;
  Bmp1.LoadFromFile ('ok.bmp');
  Bmp2.LoadFromFile ('no.bmp');

  {Windows API call}
  SetMenuItemBitmaps (Command1.Handle, Toggle1.Command, MF_BYCOMMAND,
    Bmp2.Handle, Bmp1.Handle);
end;

procedure TForm1.Toggle1Click(Sender: TObject);
begin
  Toggle1.Checked := not Toggle1.Checked;
  if Toggle1.Checked then
    Label1.Caption := 'ON'
  else
    Label1.Caption := 'OFF';
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Bmp1.Free;
  Bmp2.Free;
end;

end.

CHECK.DFM

object Form1: TForm1
  Left = 97
  Top = 243
  Width = 435
  Height = 235
  Caption = 'New Check'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = True
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 0
    Top = 48
    Width = 425
    Height = 111
    Alignment = taCenter
    AutoSize = False
    Caption = 'OFF'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -96
    Font.Name = 'Arial'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object MainMenu1: TMainMenu
    Left = 8
    Top = 8
    object Command1: TMenuItem
      Caption = '&Command'
      object Toggle1: TMenuItem
        Caption = '&Toggle'
        OnClick = Toggle1Click
      end
    end
  end
end