home *** CD-ROM | disk | FTP | other *** search
/ PC Expert 29 / Pce29cd.iso / RUNIMAGE / DELPHI40 / DEMOS / TEECHART / UPRINT.PAS < prev    next >
Pascal/Delphi Source File  |  1998-06-16  |  3KB  |  97 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Mixed Text and Chart Print Demo             }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Uprint;
  8.  
  9. { This example shows how to print both Text and Chart in the SAME PAGE }
  10.  
  11. interface
  12.  
  13. uses
  14.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  15.   Forms, Dialogs, StdCtrls, Buttons, Chart, Series, ExtCtrls, Teengine,
  16.   TeeProcs;
  17.  
  18. type
  19.   TPrintForm = class(TForm)
  20.     Chart1: TChart;
  21.     LineSeries1: TLineSeries;
  22.     BitBtn1: TBitBtn;
  23.     Edit1: TEdit;
  24.     BitBtn2: TBitBtn;
  25.     Label1: TLabel;
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure BitBtn1Click(Sender: TObject);
  28.   private
  29.     { Private declarations }
  30.   public
  31.     { Public declarations }
  32.   end;
  33.  
  34. var
  35.   PrintForm: TPrintForm;
  36.  
  37. implementation
  38.  
  39. {$R *.DFM}
  40. uses printers;
  41.  
  42. procedure TPrintForm.FormCreate(Sender: TObject);
  43. begin
  44.   LineSeries1.FillSampleValues(30); { <-- we need some random values }
  45. end;
  46.  
  47. procedure TPrintForm.BitBtn1Click(Sender: TObject);
  48. var h,w:longint;
  49. begin
  50.   Screen.Cursor := crHourGlass; { <-- nice detail }
  51.   try
  52.     Printer.BeginDoc;       { <-- start printer job }
  53.     try
  54.       { now print some text on printer.canvas }
  55.       With Printer.Canvas do
  56.       begin
  57.         Font.Name:='Arial';
  58.         Font.Size:=10;             { <-- set the font size }
  59.         Font.Style:=[];
  60.         TextOut(0,0,Edit1.Text);   { <-- print some text }
  61.       end;
  62.  
  63.       h:=Printer.PageHeight; { <-- get page height }
  64.       w:=Printer.PageWidth;  { <-- get page width }
  65.  
  66.       { And now print the chart component... }
  67.       Chart1.PrintPartial(  Rect(  w div 10,          { <-- left margin }
  68.                                    h div 3 ,          { <-- top margin }
  69.                                    w - (w div 10),    { <-- right margin }
  70.                                    h - (h div 10) )); { <-- bottom margin }
  71.  
  72.  
  73.       { print more text.... }
  74.       With Printer.Canvas do
  75.       begin
  76.         Font.Name:='Arial';
  77.         Font.Size:=12;             { <-- set the font size }
  78.         Font.Style:=[fsItalic];
  79.         TextOut(0,60,Edit1.Text+' ...again');   { <-- print some text }
  80.       end;
  81.  
  82.       Printer.EndDoc; { <-- end job and print !! }
  83.     except
  84.       on Exception do  { just in case an error happens... }
  85.       Begin
  86.         Printer.Abort;
  87.         Printer.EndDoc;
  88.         Raise;       { <-- raise up the exception !!! }
  89.       end;
  90.     end;
  91.   finally
  92.     Screen.Cursor:=crDefault; { <-- restore cursor }
  93.   end;
  94. end;
  95.  
  96. end.
  97.