home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / reporter / fishrpt1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  6.6 KB  |  243 lines

  1.  unit Fishrpt1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Reports, StdCtrls, DB, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Table1: TTable;
  13.     Table1SpeciesNo: TFloatField;
  14.     Table1Category: TStringField;
  15.     Table1Common_Name: TStringField;
  16.     Table1SpeciesName: TStringField;
  17.     Table1Lengthcm: TFloatField;
  18.     Table1Length_In: TFloatField;
  19.     Table1Notes: TMemoField;
  20.     Table1Graphic: TGraphicField;
  21.     procedure Button1Click(Sender: TObject);
  22.     procedure Button2Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.     Procedure ReportInit;
  28.     Procedure ReportDone;
  29.  
  30.     Procedure PrintHeader     ( HeaderBand  : tFixedReportBand;
  31.                                 var Status  : tBandStatus );
  32.  
  33.     Procedure InitItem        ( DetailBand  : tRecurringReportBand );
  34.     Procedure PrintItem       ( DetailBand  : tFixedReportBand;
  35.                                 var Status  : tBandStatus );
  36.  
  37.   end;
  38.  
  39. var
  40.   Form1: TForm1;
  41.  
  42. implementation
  43. Uses pStatus;
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure tForm1.ReportInit;
  48. Begin
  49.      { prevent user from pressing key while printing }
  50.      Enabled := False;
  51.  
  52.      With PrintStatusForm Do
  53.      Begin
  54.           ProgressGauge.MaxValue := 100;
  55.           ProgressGauge.Progress := 0;
  56.           CurrentPage := 1;
  57.           PrintStatus := 'Loading Data...';
  58.           PrinterName := Reporter.Printers[Reporter.PrinterIndex];
  59.           Show;
  60.           UpdateStatus;
  61.      End;
  62.  
  63.      { Open needed table(s) }
  64.      Table1.Open;
  65.  
  66.  
  67.      With PrintStatusForm Do
  68.      Begin
  69.           ProgressGauge.MaxValue := Table1.RecordCount;
  70.           PrintStatus := 'Printing...';
  71.           UpdateStatus;
  72.      End;
  73.  
  74.      { set up the margins and define the font styles }
  75.      With Reporter Do
  76.      Begin
  77.           TopMargin.AsInches := 1.5;
  78.           LeftMargin.AsInches := 0.5;
  79.           RightMargin.AsInches := 0.5;
  80.           BottomMargin.AsInches := 1.0;
  81.  
  82.           PreferredUnit := puInches;
  83.           StretchBand := True;
  84.  
  85.           Canvas.Font.Size := 10;
  86.           Canvas.Font.Style := [fsBold];
  87.           CreateFontStyle ( 'Heading1' );
  88.           CreateFontStyle ( 'Detail1' );
  89.  
  90.           Canvas.Font.Size := 18;
  91.           CreateFontStyle ( 'Heading2' );
  92.  
  93.           Canvas.Font.Size := 10;
  94.           Canvas.Font.Style := [];
  95.           CreateFontStyle ( 'Detail2' );
  96.  
  97.           Canvas.Font.Style := [fsItalic];
  98.           CreateFontStyle ( 'Detail3' );
  99.      End;
  100. End;
  101.  
  102. procedure tForm1.ReportDone;
  103. Begin
  104.      { Close opened table(s) }
  105.      Table1.Close;
  106.  
  107.      { get rid of the print status dialog and enable the form again }
  108.      Enabled := True;
  109.  
  110.      PrintStatusForm.Close;
  111. End;
  112.  
  113. procedure tForm1.PrintHeader (     HeaderBand : tFixedReportBand;
  114.                                var Status     : tBandStatus );
  115. Begin
  116.      With HeaderBand, Reporter Do
  117.      Begin
  118.           { do all the text output now }
  119.  
  120.           { save the current font }
  121.           SaveFont;
  122.  
  123.           SetFontStyle ( 'Heading1' );
  124.           TextOut ( 'Page ' + IntToStr ( PageNumber ),
  125.                     ttaRightMargin + ttaTopOfBand );
  126.  
  127.  
  128.           SetFontStyle ( 'Heading2' );
  129.           BoxTextOut ( 'Lots O'' Fishies', ttaBandHCenter + ttaBandVCenter,
  130.                        btBox, 20, 10,
  131.                        stBottomRight, 20 );
  132.  
  133.           { restore previous font }
  134.           RestoreFont;
  135.  
  136.      End;
  137. End;
  138.  
  139. procedure tForm1.InitItem ( DetailBand : tRecurringReportBand );
  140. Begin
  141.      { Here we inform the Reporter of the height of the Detail band.
  142.        This allows it to avoid breaking a record across pages.  I'm
  143.        giving each band the height of a graphic plus an 1/8th inch,
  144.        plus the height of the memo }
  145.  
  146.      With DetailBand, Reporter Do
  147.      Begin
  148.           SetBandBegin;
  149.  
  150.           PlaceDBGraphic ( Table1.FieldByName('Graphic'), ttaLeft,
  151.                            0, 0, 200, 200 );
  152.           AdjustY ( 0.125 );
  153.           DBMemoOut ( Table1.FieldByName('Notes'), 0, 7.5,
  154.                       ttaLeftMargin );
  155.  
  156.           SetBandEnd;
  157.      End;
  158. End;
  159.  
  160. procedure tForm1.PrintItem   (     DetailBand : tFixedReportBand;
  161.                                var Status     : tBandStatus );
  162. Var
  163.    SaveX : Word;
  164. Begin
  165.      With DetailBand, Reporter Do
  166.      Begin
  167.           PlaceDBGraphic ( Table1.FieldByName('Graphic'), ttaLeft, 0, 0, 200, 200 );
  168.  
  169.           { print out special notes on the fish }
  170.           AdjustY ( 0.125 );
  171.  
  172.           SetFontStyle ( 'Detail2' );
  173.           DBMemoOut ( Table1.FieldByName('Notes'), 0, 7.5,
  174.                       ttaLeftMargin );
  175.  
  176.  
  177.           { print out single line description data }
  178.           TopOfBand;
  179.  
  180.           SetFontStyle ( 'Detail1' );
  181.           TabTo ( 1.75 );
  182.           TextOut ( 'Category: ', ttaLeft );
  183.           SetFontStyle ( 'Detail2' );
  184.           TabTo ( 2.5 );
  185.           TextOut ( Table1.FieldByName('Category').AsString, ttaLeft );
  186.           NextLine;
  187.  
  188.           SetFontStyle ( 'Detail1' );
  189.           TabTo ( 1.75 );
  190.           TextOut ( 'Name: ', ttaLeft );
  191.           SetFontStyle ( 'Detail2' );
  192.           TabTo ( 2.5 );
  193.           TextOut ( Table1.FieldByName('Common_Name').AsString, ttaLeft );
  194.           NextLine;
  195.           SetFontStyle ( 'Detail3' );
  196.           TabTo ( 2.5 );
  197.           TextOut ( '    (' + Table1.FieldByName('Species Name').AsString + ')', ttaLeft );
  198.           NextLine;
  199.  
  200.           SetFontStyle ( 'Detail1' );
  201.           TabTo ( 1.75 );
  202.           TextOut ( 'Length: ', ttaLeft );
  203.           SetFontStyle ( 'Detail2' );
  204.           TabTo ( 2.5 );
  205.           TextOut ( FloatToStrF ( Table1.FieldByName('Length_IN').AsFloat, ffNumber, 5, 2 ) + ' in.', ttaLeft );
  206.           SetFontStyle ( 'Detail3' );
  207.           TextOut ( '    (' + FloatToStrF ( Table1.FieldByName('Length (cm)').AsFloat, ffNumber, 6, 2 ) + ' cm)', ttaleft );
  208.  
  209.      End;
  210.  
  211.      With PrintStatusForm Do
  212.      Begin
  213.           ProgressGauge.Progress := ProgressGauge.Progress + 1;
  214.           CurrentPage := Reporter.PageNumber;
  215.           UpdateStatus;
  216.      End;
  217.  
  218.      Table1.Next;
  219.      If PrintStatusForm.Canceled Then
  220.         Status := bsAbort
  221.      Else If Table1.EOF Then
  222.         Status := bsDone;
  223. End;
  224.  
  225.  
  226. procedure TForm1.Button1Click(Sender: TObject);
  227. begin
  228.      Reporter.OnReportInit := ReportInit;
  229.      Reporter.OnReportDone := ReportDone;
  230.  
  231.      Reporter.AddHeader ( PrintHeader );
  232.      Reporter.AddDetail ( InitItem, PrintItem );
  233.  
  234.      Reporter.Run;
  235. end;
  236.  
  237. procedure TForm1.Button2Click(Sender: TObject);
  238. begin
  239.      Reporter.Abort;
  240. end;
  241.  
  242. end.
  243.