home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / delphi / cbsuite.lzh / SU1SRC.ZIP / FDEMO15.PAS < prev    next >
Pascal/Delphi Source File  |  1996-11-24  |  8KB  |  233 lines

  1. unit Fdemo15;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  6.   StdCtrls, PrnWin, ExtCtrls, DBTables, DB, Printers, DBCtrls, CB_Types,
  7.   Grids, DBGrids, DBPrnWin, CB_MFunc;
  8.  
  9. type
  10.   TForm15 = class(TForm)
  11.     Bevel1: TBevel;
  12.     Memo1: TMemo;
  13.     Table1: TTable;
  14.     Table2: TTable;
  15.     Query1: TQuery;
  16.     Query2: TQuery;
  17.     Query3: TQuery;
  18.     DataSource1: TDataSource;
  19.     DataSource2: TDataSource;
  20.     DataSource3: TDataSource;
  21.     DataSource4: TDataSource;
  22.     DataSource5: TDataSource;
  23.     Query1SpeciesNo: TFloatField;
  24.     Query1Category: TStringField;
  25.     Query1Common_Name: TStringField;
  26.     Table1NAME: TStringField;
  27.     Table1SIZE: TSmallintField;
  28.     Table1WEIGHT: TSmallintField;
  29.     Table1AREA: TStringField;
  30.     Query2Name: TStringField;
  31.     Query2Capital: TStringField;
  32.     Query2Continent: TStringField;
  33.     Query2Population: TFloatField;
  34.     Query3Company: TStringField;
  35.     Query3Phone: TStringField;
  36.     Query3LastInvoiceDate: TDateTimeField;
  37.     Preview: TBitBtn;
  38.     Exit: TBitBtn;
  39.     Table2IND_CODE: TSmallintField;
  40.     Table2IND_NAME: TStringField;
  41.     Table2LONG_NAME: TStringField;
  42.     Table1BMP: TBlobField;
  43.     DBImage1: TDBImage;
  44.     DBImage2: TDBImage;
  45.     Query1Graphic: TGraphicField;
  46.     DBGrid1: TDBGrid;
  47.     DBPrintWin1: TDBPrintWin;
  48.     procedure PreviewClick(Sender: TObject);
  49.   private
  50.     { Private declarations }
  51.   public
  52.     { Public declarations }
  53.   end;
  54.  
  55. var
  56.   Form15: TForm15;
  57.  
  58. implementation
  59.  
  60. {$R *.DFM}
  61.  
  62. procedure TForm15.PreviewClick(Sender: TObject);
  63. var
  64.     i: Integer;
  65.    Right, Bottom, Top: Real;
  66. begin
  67.    DBPrintWin1.BeginPrint;
  68.    DBGrid1.Visible := True;
  69.  
  70.    { This will take a bit of programming! }
  71.  
  72.    { Set a nice big font }
  73.    DBPrintWin1.NewFont ('Arial',20,True,True,True); { The 3 True's are for Bold,
  74.                                                    Italic and Underline }
  75.  
  76.    { And change the color to Red }
  77.    DBPrintWin1.SetTheTextColor (RGB(255,0,0));
  78.  
  79.    { Draw the text in the Center of the page }
  80.    DBPrintWin1.DrawText( 1.0,poCenter,'A 4-Page Demo for TPrintWin');
  81.  
  82.    { Draw the first table }
  83.    DBPrintWin1.NewFont ('Arial',14,False,False,True);
  84.    DBPrintWin1.SetTheTextColor (RGB(0,0,255));
  85.    DBPrintWin1.DrawText( 2.0,poLeft,'Here is a list of animals from Table1');
  86.    DBPrintWin1.DrawWindow( 2.3, poLeft, DBGrid1);
  87.  
  88.  
  89.    { Draw the 2nd table }
  90.    DBPrintWin1.SetTheTextColor (RGB(0,0,255));
  91.    DBPrintWin1.DrawText( 4.6,poLeft,'Here is another Table');
  92.    DBPrintWin1.DrawWindow( 5.0, poLeft, DBGrid1);
  93.  
  94.    { Draw the 2nd table again}
  95.    DBPrintWin1.SetTheTextColor (RGB(0,0,0));
  96.    DBPrintWin1.DrawText( 2.0,poRight,'Repeating Table2');
  97.    DBPrintWin1.DrawWindow( 2.3, poRight, DBGrid1);
  98.  
  99.    { And the 1st Query }
  100.    DBPrintWin1.SetTheTextColor (RGB(0,255,0));
  101.    DBPrintWin1.DrawText( 4.6,poRight,'Here is a Query');
  102.    DBPrintWin1.DrawWindow( 5.0, poRight, DBGrid1);
  103.  
  104.    { And Draw some lines in different colors, added some Printer info }
  105.    Bottom := DBPrintWin1.PageHeight - 1;
  106.    Top := Bottom - 1.5;
  107.    Right := 1.01;
  108.    for i := 0 to 30 do begin
  109.        if i mod 3 = 0 then
  110.            DBPrintWin1.SelectPen(1, RGB(255,0,0));
  111.        if i mod 3 = 1 then
  112.            DBPrintWin1.SelectPen(1, RGB(0,255,0));
  113.        if i mod 3 = 2 then
  114.            DBPrintWin1.SelectPen(1, RGB(0,0,255));
  115.  
  116.       DBPrintWin1.DrawLine( 0.5, Top, Right, Bottom);
  117.       Top := Top + 0.03;
  118.       Right := Right + 0.07;
  119.       Bottom := Bottom - 0.03;
  120.  
  121.       DBPrintWin1.DrawLine( 0.5, Bottom, Right, Top);
  122.    end;
  123.  
  124.    { And Frame them nicely }
  125.    Bottom := DBPrintWin1.PageHeight - 1;
  126.    Top := Bottom - 1.5;
  127.    DBPrintWin1.SetTheTextColor (RGB(0,0,255));
  128.    DBPrintWin1.DrawText(Top - 0.3,poLeft,'Draw a few lines');
  129.    DBPrintWin1.DrawLine(0.5,Top,Right,Top);
  130.    DBPrintWin1.DrawLine(0.5,Bottom,Right,Bottom);
  131.    DBPrintWin1.DrawLine(0.5,Top,0.5,Bottom);
  132.    DBPrintWin1.DrawLine(Right,Top,Right,Bottom);
  133.  
  134.    { Print a Bitmap }
  135.    DBPrintWin1.DrawText(Top - 0.3,poRight,'Draw an Image');
  136.    DBPrintWin1.PrintBitmap(DBPrintWin1.PageWidth -2.5,Top,2,2,DBImage1.Picture.Bitmap);
  137.  
  138.    { Now we switch the header on again }
  139.    DBPrintWin1.HeaderEnabled := True;
  140.    DBPrintWin1.HeaderFilled := True;
  141.    DBPrintWin1.HeaderOutlined := True;
  142.    DBPrintWin1.HeaderStringCenter := 'Ah, Now we have a header again';
  143.  
  144.    { And go on to the second page }
  145.    DBPrintWin1.NewPage;
  146.  
  147.    { Draw the text in the Center of the 2nd page }
  148.    DBPrintWin1.NewFont ('Arial',20,True,True,True);
  149.    DBPrintWin1.DrawText( 1.6,poCenter,'2nd Page of a 4-Page Demo for TPrintWin');
  150.  
  151.    { Draw the 2nd Query }
  152.    DBPrintWin1.NewFont ('Arial',14,False,False,True);
  153.    DBPrintWin1.SetTheTextColor (RGB(0,0,255));
  154.    DBPrintWin1.DrawText( 2.3,poCenter,'Name some countries in North America');
  155.    DBPrintWin1.DrawText( 2.6,poCenter,'and keep to the Center');
  156.    DBGrid1.Datasource := Datasource2;
  157.    DBPrintWin1.DrawWindow( 3, poCenter, DBGrid1);
  158.  
  159. {   PrintWin1.DrawQuery( 3, poCenter, Query2, False, False);}
  160.  
  161.    { Draw the 2nd Query }
  162.    DBPrintWin1.NewFont ('Arial',14,True,False,True);
  163.    DBPrintWin1.SetTheTextColor (RGB(255,0,0));
  164.    DBPrintWin1.DrawText( 5.6,poCenter,'And now I have to make some phone calls');
  165.    DBPrintWin1.DrawText( 6,poCenter,'and keep to the Center');
  166.    DBGrid1.Visible := True;
  167.    DBPrintWin1.SetColumnWidth(DBGrid1, 'NAME', 1.0);
  168.    DBPrintWin1.SetColumnWidth(DBGrid1, 'WEIGHT', 2.0);
  169.    DBPrintWin1.DrawWindow( 6.3, poCenter, DBGrid1);
  170.    Table1.First;
  171.  
  172.  
  173.    { and Maybe just add a single Record from the phone calls query }
  174.    DBPrintWin1.NewFont ('Arial',14,True,False,True);
  175.    DBPrintWin1.SetTheTextColor (RGB(0,0,0));
  176.    DBPrintWin1.DrawText( 8,poLeft,'And now for a single record');
  177.    DBPrintWin1.NewFont ('Arial',14,False,True,False);
  178.    DBPrintWin1.DrawQueryRecord( 1, 8.3, Query3);
  179.  
  180.    { And go on to the 3rd page }
  181.    DBPrintWin1.NewPage;
  182.  
  183.    { Here we need a heading }
  184.    DBPrintWin1.NewFont ('Arial',20,True,True,True);
  185.    DBPrintWin1.DrawText( 1.6,poCenter,'3rd Page of a 4-Page Demo for TPrintWin');
  186.  
  187.    { Now we need an image, We might as well use some animals from
  188.      table1
  189.      Note: The DBImage component is used to extract the bitmap and
  190.      TPrintWin Prints it}
  191.  
  192.    { First draw a grid }
  193.    DBPrintWin1.NewFont ('Arial',14,True,False,False);
  194.    DBPrintWin1.DrawGrid(0.5,2.3,2.3,2.3,3,3);
  195.    for i := 0 to 2 do begin
  196.      DBPrintWin1.DrawTextAt( 0.8,2.4+(2.3*i),Table1Name.AsString);
  197.      DBPrintWin1.PrintBitmap(0.8,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  198.      Table1.Next;
  199.  
  200.      { There are only 7 images in the table, so return }
  201.      if i < 2 then begin
  202.         DBPrintWin1.DrawTextAt( 3.1,2.4+(2.3*i),Table1Name.AsString);
  203.         DBPrintWin1.PrintBitmap(3.1,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  204.         Table1.Next;
  205.         DBPrintWin1.DrawTextAt( 5.4,2.4+(2.3*i),Table1Name.AsString);
  206.         DBPrintWin1.PrintBitmap(5.4,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  207.         Table1.Next;
  208.      end;
  209.    end;
  210.  
  211.    { And go on to the 4rd page and get the BLOB's from the Query}
  212.    DBPrintWin1.NewPage;
  213.  
  214.    { Here we need a heading }
  215.    DBPrintWin1.NewFont ('Arial',14,True,True,True);
  216.    DBPrintWin1.DrawText( 1.6,poCenter,'4th Page of a 4-Page Demo for TPrintWin');
  217.    Query1.First;
  218.    for i := 0 to 2 do begin
  219.      DBPrintWin1.PrintBitmap(1,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  220.      Query1.Next;
  221.  
  222.      DBPrintWin1.PrintBitmap(3.3,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  223.      Query1.Next;
  224.      DBPrintWin1.PrintBitmap(5.6,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  225.      Query1.Next;
  226.    end;
  227.  
  228.  
  229.    DBPrintWin1.EndPrint;
  230. end;
  231.  
  232. end.
  233.