Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 5

Project NAVIG

Project Structure


NAVIG.DPR

program Navig;

uses
  Forms,
  RptForm in 'RptForm.pas' {ReportForm},
  NavForm in 'NavForm.pas' {Navigator};

{$R *.RES}

begin
  Application.CreateForm(TNavigator, Navigator);
  Application.CreateForm(TReportForm, ReportForm);
  Application.Run;
end.

RPTFORM.PAS

unit RptForm;

interface

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

type
  TReportForm = class(TForm)
    QuickRep1: TQuickRep;
    QRBand3: TQRBand;
    QRBand2: TQRBand;
    QRBand1: TQRBand;
    QRSysData1: TQRSysData;
    QRSysData2: TQRSysData;
    QRDBText1: TQRDBText;
    QRDBText2: TQRDBText;
    QRDBText3: TQRDBText;
    QRExpr1: TQRExpr;
    QRLabel1: TQRLabel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ReportForm: TReportForm;

implementation

uses Navform;

{$R *.DFM}

end.

NAVFORM.PAS

unit NavForm;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics,
  Controls, Forms, Dialogs, ExtCtrls, DBCtrls, StdCtrls,
  Mask, DB, DBTables, Printers;

type
  TNavigator = class(TForm)
    PrintButton: TButton;
    PrintAllButton: TButton;
    PrintFormButton: TButton;
    DBNavigator1: TDBNavigator;
    DBEdit1: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    Label3: TLabel;
    Table1: TTable;
    DataSource1: TDataSource;
    ButtonReport: TButton;
    Table1Name: TStringField;
    Table1Capital: TStringField;
    Table1Continent: TStringField;
    Table1Population: TFloatField;
    procedure PrintButtonClick(Sender: TObject);
    procedure PrintFormButtonClick(Sender: TObject);
    procedure PrintAllButtonClick(Sender: TObject);
    procedure ButtonReportClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Navigator: TNavigator;

implementation

uses RptForm;

{$R *.DFM}

procedure TNavigator.PrintButtonClick(Sender: TObject);
var
  PrintFile: TextFile;
begin
  {assing the printer to a file}
  AssignPrn (PrintFile);
  Rewrite (PrintFile);
  try
    {set the font of the form, and output each element}
    Printer.Canvas.Font := Font;
    Writeln (PrintFile, Label1.Caption,
      ' ', DBEdit1.Text);
    Writeln (PrintFile, Label2.Caption,
      ' ', DBEdit2.Text);
    Writeln (PrintFile, Label3.Caption,
      ' ', DBEdit3.Text);
  finally
    {close the printing process}
    System.CloseFile (PrintFile);
  end;
end;

procedure TNavigator.PrintFormButtonClick(Sender: TObject);
begin
  Print;
end;

procedure TNavigator.PrintAllButtonClick(Sender: TObject);
var
  Bookmark: TBookmark;
  PrintFile: TextFile;
begin
  {assign the printer to a file}
  AssignPrn (PrintFile);
  Rewrite (PrintFile);
  {set the font of the form}
  Printer.Canvas.Font := Font;
  {store the current position, crating a new bookmark}
  Bookmark := Table1.GetBookmark;
  Table1.DisableControls;
  try
    Table1.First;
    while not Table1.EOF do
    begin
      {output the three fields, and a blank line}
      Writeln (PrintFile, 'Country: ',
        Table1.FieldByName ('Name').AsString);
      Writeln (PrintFile, 'Capital: ',
        Table1.FieldByName ('Capital').AsString);
      Writeln (PrintFile, 'Continent: ',
        Table1.FieldByName ('Continent').AsString);
      Writeln (PrintFile);
      Table1.Next;
    end;
  finally
    {go back to the bookmark and destroy it}
    Table1.GotoBookmark (Bookmark);
    Table1.FreeBookmark (Bookmark);
    Table1.EnableControls;
    System.CloseFile (PrintFile);
  end;
end;

procedure TNavigator.ButtonReportClick(Sender: TObject);
begin
  ReportForm.QuickRep1.Preview;
end;

end.

RPTFORM.DFM

object ReportForm: TReportForm
  Left = 6
  Top = 133
  Width = 790
  Height = 272
  HorzScrollBar.Range = 1200
  VertScrollBar.Position = 111
  VertScrollBar.Range = 2000
  AutoScroll = False
  Caption = 'ReportForm'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -13
  Font.Name = 'Arial'
  Font.Style = []
  OldCreateOrder = True
  Scaled = False
  PixelsPerInch = 96
  TextHeight = 16
  object QuickRep1: TQuickRep
    Left = 0
    Top = -111
    Width = 794
    Height = 1123
    Frame.Color = clBlack
    Frame.DrawTop = False
    Frame.DrawBottom = False
    Frame.DrawLeft = False
    Frame.DrawRight = False
    DataSet = Navigator.Table1
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = []
    Functions.Strings = (
      'PAGENUMBER'
      'COLUMNNUMBER'
      'REPORTTITLE')
    Functions.DATA = (
      '0'
      '0'
      '''''')
    Options = [FirstPageHeader, LastPageFooter]
    Page.Columns = 1
    Page.Orientation = poPortrait
    Page.PaperSize = A4
    Page.Values = (
      100
      2970
      100
      2100
      100
      100
      0)
    PrinterSettings.Copies = 1
    PrinterSettings.Duplex = False
    PrinterSettings.FirstPage = 0
    PrinterSettings.LastPage = 0
    PrinterSettings.OutputBin = First
    PrintIfEmpty = True
    ReportTitle = 'Countries Report'
    SnapToGrid = True
    Units = MM
    Zoom = 100
    object QRBand3: TQRBand
      Left = 38
      Top = 159
      Width = 718
      Height = 107
      Frame.Color = clBlack
      Frame.DrawTop = True
      Frame.DrawBottom = False
      Frame.DrawLeft = False
      Frame.DrawRight = False
      AlignToBottom = False
      Color = clWhite
      ForceNewColumn = False
      ForceNewPage = False
      Size.Values = (
        283.104166666667
        1899.70833333333)
      BandType = rbPageFooter
      object QRExpr1: TQRExpr
        Left = 246
        Top = 16
        Width = 99
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          650.875
          42.3333333333333
          261.9375)
        Alignment = taRightJustify
        AlignToBand = False
        AutoSize = False
        AutoStretch = False
        Color = clWhite
        Master = QuickRep1
        ResetAfterPrint = False
        Transparent = False
        WordWrap = True
        Expression = 'SUM(Population)'
        Mask = '###,###,###'
        FontSize = 10
      end
      object QRLabel1: TQRLabel
        Left = 144
        Top = 16
        Width = 98
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          381
          42.3333333333333
          259.291666666667)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Caption = 'Total Population:'
        Color = clWhite
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
    end
    object QRBand2: TQRBand
      Left = 38
      Top = 88
      Width = 718
      Height = 71
      Frame.Color = clBlack
      Frame.DrawTop = False
      Frame.DrawBottom = False
      Frame.DrawLeft = False
      Frame.DrawRight = False
      Frame.Width = 0
      AlignToBottom = False
      Color = clWhite
      ForceNewColumn = False
      ForceNewPage = False
      Size.Values = (
        187.854166666667
        1899.70833333333)
      BandType = rbDetail
      object QRDBText1: TQRDBText
        Left = 34
        Top = 16
        Width = 35
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          89.9583333333333
          42.3333333333333
          92.6041666666667)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Color = clWhite
        DataSet = Navigator.Table1
        DataField = 'Name'
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
      object QRDBText2: TQRDBText
        Left = 34
        Top = 40
        Width = 41
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          89.9583333333333
          105.833333333333
          108.479166666667)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        AutoStretch = False
        Color = clWhite
        DataSet = Navigator.Table1
        DataField = 'Capital'
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
      object QRDBText3: TQRDBText
        Left = 246
        Top = 16
        Width = 123
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          650.875
          42.3333333333333
          325.4375)
        Alignment = taRightJustify
        AlignToBand = False
        AutoSize = False
        AutoStretch = False
        Color = clWhite
        DataSet = Navigator.Table1
        DataField = 'Population'
        Mask = '###,###,###'
        Transparent = False
        WordWrap = True
        FontSize = 10
      end
    end
    object QRBand1: TQRBand
      Left = 38
      Top = 38
      Width = 718
      Height = 50
      Frame.Color = clTeal
      Frame.DrawTop = True
      Frame.DrawBottom = True
      Frame.DrawLeft = True
      Frame.DrawRight = True
      Frame.Width = 2
      AlignToBottom = False
      Color = clWhite
      ForceNewColumn = False
      ForceNewPage = False
      Size.Values = (
        132.291666666667
        1899.70833333333)
      BandType = rbPageHeader
      object QRSysData1: TQRSysData
        Left = 32
        Top = 16
        Width = 84
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          84.6666666666667
          42.3333333333333
          222.25)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        Color = clWhite
        Data = qrsPageNumber
        Text = 'Page: '
        Transparent = False
        FontSize = 10
      end
      object QRSysData2: TQRSysData
        Left = 442
        Top = 16
        Width = 220
        Height = 17
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        Size.Values = (
          44.9791666666667
          1169.45833333333
          42.3333333333333
          582.083333333333)
        Alignment = taLeftJustify
        AlignToBand = False
        AutoSize = True
        Color = clWhite
        Data = qrsDateTime
        Text = 'Countries Report, printed  '
        Transparent = False
        FontSize = 10
      end
    end
  end
end

NAVFORM.DFM

object Navigator: TNavigator
  Left = 148
  Top = 122
  Width = 366
  Height = 227
  Caption = 'Navigator'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 40
    Top = 56
    Width = 39
    Height = 13
    Caption = 'Country:'
  end
  object Label2: TLabel
    Left = 40
    Top = 91
    Width = 35
    Height = 13
    Caption = 'Capital:'
  end
  object Label3: TLabel
    Left = 40
    Top = 124
    Width = 48
    Height = 13
    Caption = 'Continent:'
  end
  object PrintButton: TButton
    Left = 8
    Top = 160
    Width = 81
    Height = 25
    Caption = 'Print'
    TabOrder = 0
    OnClick = PrintButtonClick
  end
  object PrintAllButton: TButton
    Left = 96
    Top = 160
    Width = 81
    Height = 25
    Caption = 'Print All'
    TabOrder = 1
    OnClick = PrintAllButtonClick
  end
  object PrintFormButton: TButton
    Left = 184
    Top = 160
    Width = 81
    Height = 25
    Caption = 'Print Form'
    TabOrder = 2
    OnClick = PrintFormButtonClick
  end
  object DBNavigator1: TDBNavigator
    Left = 0
    Top = 0
    Width = 358
    Height = 25
    DataSource = DataSource1
    VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbInsert, nbEdit, nbPost, nbCancel]
    Align = alTop
    Flat = True
    TabOrder = 3
  end
  object DBEdit1: TDBEdit
    Left = 104
    Top = 52
    Width = 169
    Height = 21
    DataField = 'Name'
    DataSource = DataSource1
    TabOrder = 4
  end
  object DBEdit2: TDBEdit
    Left = 104
    Top = 86
    Width = 169
    Height = 21
    DataField = 'Capital'
    DataSource = DataSource1
    TabOrder = 5
  end
  object DBEdit3: TDBEdit
    Left = 104
    Top = 120
    Width = 169
    Height = 21
    DataField = 'Continent'
    DataSource = DataSource1
    TabOrder = 6
  end
  object ButtonReport: TButton
    Left = 272
    Top = 160
    Width = 75
    Height = 25
    Caption = 'Report...'
    TabOrder = 7
    OnClick = ButtonReportClick
  end
  object Table1: TTable
    Active = True
    DatabaseName = 'DBDEMOS'
    TableName = 'COUNTRY.DB'
    Left = 16
    Top = 88
    object Table1Name: TStringField
      FieldName = 'Name'
      Size = 24
    end
    object Table1Capital: TStringField
      FieldName = 'Capital'
      Size = 24
    end
    object Table1Continent: TStringField
      FieldName = 'Continent'
      Size = 24
    end
    object Table1Population: TFloatField
      FieldName = 'Population'
      DisplayFormat = '###,###,###'
    end
  end
  object DataSource1: TDataSource
    DataSet = Table1
    Left = 16
    Top = 40
  end
end