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 5

Project IMAGEV

Project Structure


IMAGEV.DPR

program Imagev;

uses
  Forms,
  ImageF in 'ImageF.pas' {ViewerForm};

{$R *.RES}

begin
  Application.CreateForm(TViewerForm, ViewerForm);
  Application.Run;
end.

IMAGEF.PAS

unit ImageF;

interface

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

type
  TViewerForm = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Open1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Help1: TMenuItem;
    AboutImageViewer1: TMenuItem;
    OpenDialog1: TOpenDialog;
    Options1: TMenuItem;
    Stretch1: TMenuItem;
    Image1: TImage;
    Center1: TMenuItem;
    procedure Open1Click(Sender: TObject);
    procedure Stretch1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure AboutImageViewer1Click(Sender: TObject);
    procedure Center1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ViewerForm: TViewerForm;

implementation

              {$R *.DFM}

procedure TViewerForm.Open1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    Image1.Picture.LoadFromFile (OpenDialog1.FileName);
    Caption := 'Image Viewer - ' + OpenDialog1.FileName;
  end;
end;

procedure TViewerForm.Stretch1Click(Sender: TObject);
begin
  Image1.Stretch := not Image1.Stretch;
  Stretch1.Checked := Image1.Stretch;
end;

procedure TViewerForm.Center1Click(Sender: TObject);
begin
  Image1.Center := not Image1.Center;
  Center1.Checked := Image1.Center;
end;

procedure TViewerForm.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TViewerForm.AboutImageViewer1Click(Sender: TObject);
begin
  MessageDlg ('Image Viewer is an example'
    + #13'of the book "Mastering Delphi"'
    + #13'written by Marco Cantý',
    mtInformation, [mbOk], 0);
end;

end.

IMAGEF.DFM

object ViewerForm: TViewerForm
  Left = 182
  Top = 149
  Width = 434
  Height = 299
  Caption = 'Image Viewer'
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  Menu = MainMenu1
  PixelsPerInch = 96
  TextHeight = 16
  object Image1: TImage
    Left = 0
    Top = 0
    Width = 426
    Height = 253
    Align = alClient
  end
  object MainMenu1: TMainMenu
    Left = 16
    Top = 16
    object File1: TMenuItem
      Caption = '&File'
      object Open1: TMenuItem
        Caption = '&Open...'
        OnClick = Open1Click
      end
      object N1: TMenuItem
        Caption = '-'
      end
      object Exit1: TMenuItem
        Caption = '&Exit'
        OnClick = Exit1Click
      end
    end
    object Options1: TMenuItem
      Caption = '&Options'
      object Stretch1: TMenuItem
        Caption = '&Stretch'
        OnClick = Stretch1Click
      end
      object Center1: TMenuItem
        Caption = '&Center'
        OnClick = Center1Click
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      object AboutImageViewer1: TMenuItem
        Caption = '&About Image Viewer...'
        OnClick = AboutImageViewer1Click
      end
    end
  end
  object OpenDialog1: TOpenDialog
    FileEditStyle = fsEdit
    Filter = 'Bitmap (*.bmp)|*.bmp|Icon (*.ico)|*.ico|Metafile (*.wmf)|*.wmf'
    Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist]
    Left = 56
    Top = 16
  end
end