ף
    ӭʹ21ṩ߰

   ӡؼScreenReport for Delphiʹ˵

һ˵
    ScreenReportӡؼһõDelphiӡؼʹؼӦóкܷ
ؽݱԤʾʹӡ

װ
        
    1.Delphi 1.0 װ
    
    ΪDelphiĿؼװ
    һ\Delphi1 Ŀ¼µļDelphiĿ¼LIBĿ¼£
    ڶѡOptions˵ġInstall Components...Ӳ˵Install Componentsڣ
    㡰Addť
    ġ㡰Browseť
    塢ѡPRINTP.DCU
    㡰 OkťDelphi±ϵͳ⡣

    ְװϵ,һDelphiBinĿ¼µcomplib.dclʹõĿؼļ
    ,һ·ǷгͻĻ汾ļ,°װDelphiһ
    Ϳɽ

    2.Delphi 3 ,Delphi 4Delphi5װ

    Ϊװ
    һӦ汾Ŀ¼µļDelphiĿ¼LIBĿ¼£
    ڶѡComponent˵ġInstall Packages...
    㡰Addť
    ġѡӦScreport.dpl(Delphi3)Screport.bpl(Delphi4Delphi5) 㡰򿪡
    塢㡰OKť
    
    ************************************* ע ******************************************
    
    ؼװϺѡ'Tools'->'Environment Options'˵,'Library'ҳ'Library Path'
          ֹPrintp.dcu ڵ·ӳʱ޷ҵprintp.dcu
      
    ************************************************************************************* 


******************************** ر˵ *******************************************

  · PrintReportԭPrinterView(p1,p2),PrintReportκβ
  ԺĻPrintReportӡοµ˵

*********************************************************************************

Ҫ

    1. PrnPanel: ҪӡڵPanelΪTPanel
       ֻиPanelϵݲܴӡûиPanelͨOnPaint¼дӡ
       ֻҪ˴ԣOnPaintͲá
    
    2. DetailDatasource: ҪѭӡԴDBGridĴӡ,ΪTDatasource
        ҪӡDBGrid,ͱôԡұҪӡDBGridDataSourceͬȷӡ
        ΪDatasourceм¼Ķֱӹϵҳͱĳȡ
        ҪӡĿؼûDBGridͲá

************************************************************************************  
    ֻҪöһͿӡˡ
    »ĸ˳Խ˵

***********************************************************************************

    4. AllowUserSet: Ƿû̬ñԡοParaFileԡ
        ֵ       
        ========================
        True     
        False    

    5. BottomMarginTopMarginLeftMarginRightMargin :  ҳ߽磬ԺΪλӡ
        򲻵ֽߡ

    6. BottomTitle: ݡΪString
       Ϊգӡҳݣӡҳݡҳпɴò:
         %BOTTOM% :д,ҳݽӡҳױ,ӱβӡ
         %GETPAGE%:ҳ
         %GETPAGESCOUNT%:ҳ
         %GETDATE%: ڱ
         %GETTIME%: ʱ

         %LEFT% :       Ʒ
         %CENTER% : пƷ
         %RIFHT% :     ҿƷ

       ע:ϱֻôд,ɷBottomTitleеط
       :
       'ʮһƱ%BOTTOM%  %GETDATE%  %GETTIME%  %GETPAGE%ҳ %GETPAGESCOUNT%ҳ'

    7. BottomTitleFont: еԡΪTFont

    8. DrawControlBorder: ǷӡĳЩؼTEditȣı߿ΪBoolean
        ֵ       
        ========================
        True     ӡؼı߿
        False    ӡؼı߿

    9. DrawMargins: ԤʱǷʾҳ߽磨ӡڴӡֽϿԴӡķΧΪBoolean
        ֵ       
        ========================
        True     ʾҳ߽
        False    ʾҳ߽

    10. FitPageHeight:ֽԶš
        ֵ       
        ========================
        True     Զţʱ(VMiddle)Ч
        False    

    11. FitPageWidth:ֽԶš
        ֵ       
        ========================
        True     Զţʱ(HMiddle)Ч
        False    

    12. FootLine:Ƿҳź
        ֵ       
        ========================
        True     
        False    

    13. FootTitle: ҳݡΪStringͬɴͱμBottomTitle;

    14. FootTitleFont: ҳеԡΪTFont

    15. GridBorderStyle: DBGrid͡ΪTGBStyle
        ֵ         
        ===============================
        gbsNone   ӡָ
        gbsHorz   ӡˮƽָ
        gbsVert   ӡֱָ
        gbsBottom ӡˮƽָ
        gbsBoth   ӡˮƽֱָ

    16. HeadLine:Ƿҳü
        ֵ       
        ========================
        True     
        False    

    17. HeadTitle: ҳüݡΪStringͬɴͱμBottomTitle;

    18. headTitleFont: ҳüеԡΪTFont

    19. HMiddle: ӡǷˮƽСΪBooleanFitPageWidthΪTrueʱЧ
        ֵ       
        ========================
        True     ˮƽ
        False    

    20. myOrientation: ӡΪTPrinterOrientation
        ֵ          
        ===============================
        poPortrait  ӡ
        poLandscape ӡ

    21. PageCount: ҳʱȡʱɲá

    22. PageSum: ǷDBGridֵֶνԶҳϼơΪBoolean
        ֵ       
        =========================
        True     Զ㲢ӡҳϼ
        False    ӡҳϼ

    23. PageSumLabel: ҳϼеı⡣ȱʡΪҳϼơ޸ġ

    24. ParaFile:  òļ֡
          ļڶ̬úԶýڴļԺ󶼰˲ӡ
          ļ԰еáAllowUserSet=True,һļÿδ
          ӡǰҪá

    25. PreviewMode: ǷԤʾӡݡΪBoolean
        ֵ       
        =========================
        True     Ԥʾ
        False    ԤʾֱӴӡ

    26. PrinterPaperSize: ôӡֽ͡ΪTPrinterPaperSize
        ֵ          
        ===============================
          ppsFirst        -->DMPAPER_FIRST	DMPAPER_LETTER
          ppsLetter       -->DMPAPER_LETTER	Letter, 8 1/2 x 11 in.
          ppsLetterSmall  -->DMPAPER_LETTERSMALL	Letter Small, 8 1/2 x 11 in.
          ppsTabloid      -->DMPAPER_TABLOID	Tabloid, 11 x 17 in.
          ppsLedger       -->DMPAPER_LEDGER	Ledger, 17 x 11 in.
          ppsLegal        -->DMPAPER_LEGAL	Legal, 8 1/2 x 14 in.
          ppsStatement    -->DMPAPER_STATEMENT	Statement, 5 1/2 x 8 1/2 in.
          ppsExecutive    -->DMPAPER_EXECUTIVE	Executive, 7 1/2 x 10 1/2 in.
          ppsA3           -->DMPAPER_A3	        A3, 297 x 420 mm
          ppsA4           -->DMPAPER_A4	        A4, 210 x 297 mm
          ppsA4Small      -->DMPAPER_A4SMALL	A4 Small, 210 x 297 mm
          ppsA5           -->DMPAPER_A5	        A5, 148 x 210 mm
          ppsB4           -->DMPAPER_B4	        B4, 250 x 354 mm
          ppsB5           -->DMPAPER_B5          	B5, 182 x 257 mm
          ppsFolio        -->DMPAPER_FOLIO	Folio, 8 1/2 x 13 in.
          ppsQuarto       -->DMPAPER_QUARTO	Quarto, 215 x 275 mm
          pps10X14        -->DMPAPER_10X14	10 x 14 in.
          pps11X17        -->DMPAPER_11X17	11 x 17 in.
          ppsNote         -->DMPAPER_NOTE	Note,   8 1/2 x 11 in.
          ppsEnv9         -->DMPAPER_ENV_9	Envelope #9, 3 7/8 x 8 7/8 in.
          ppsEnv10        -->DMPAPER_ENV_10	Envelope #10, 4 1/8 x 9 1/2 in.
          ppsEnv11        -->DMPAPER_ENV_11	Envelope #11, 4 1/2 x 10 3/8 in.
          ppsEnv12        -->DMPAPER_ENV_12	Envelope #12, 4 1/2 x 11 in.
          ppsEnv14        -->DMPAPER_ENV_14	Envelope #14, 5 x 11 1/2 in.
          ppsCSheet       -->DMPAPER_CSHEET	C size sheet
          ppsDSheet       -->DMPAPER_DSHEET	D size sheet
          ppsESheet       -->DMPAPER_ESHEET	E size sheet

          ppsEnvDL        -->DMPAPER_ENV_DL	Envelope DL, 110 x 220 mm
          ppsEnvC3        -->DMPAPER_ENV_C3	Envelope C3, 324 x 458 mm
          ppsEnvC4        -->DMPAPER_ENV_C4	Envelope C4, 229 x 324 mm
          ppsEnvC5        -->DMPAPER_ENV_C5	Envelope C5, 162 x 229 mm
          ppsEnvC6        -->DMPAPER_ENV_C6	Envelope C6, 114 x 162 mm
          ppsEnvC65       -->DMPAPER_ENV_C65	Envelope C65, 114 x 229 mm
          ppsEnvB4        -->DMPAPER_ENV_B4	Envelope B4, 250 x 353 mm
          ppsEnvB5        -->DMPAPER_ENV_B5	Envelope B5, 176 x 250 mm
          ppsEnvB6        -->DMPAPER_ENV_B6	Envelope B6, 176 x 125 mm
          ppsEnvItaly     -->DMPAPER_ENV_ITALY	Envelope, 110 x 230 mm
          ppsEnvMonarch   -->DMPAPER_ENV_MONARCH	Envelope Monarch, 3 7/8 x 7 1/2 in.
          ppsEnvPersonal  -->DMPAPER_ENV_PERSONAL	Envelope, 3 5/8 x 6 1/2 in.
          ppsFanfold_US   -->DMPAPER_FANFOLD_US	U.S. Standard Fanfold, 14 7/8 x 11 in.
          ppsFanfold_STD  -->DMPAPER_FANFOLD_STD_GERMAN	German Standard Fanfold, 8 1/2 x 12 in.
          ppsFanfold_LGL  -->DMPAPER_FANFOLD_LGL_GERMAN	German Legal Fanfold, 8 1/2 x 13 in.
          ppsLast         -->DMPAPER_LAST	German Legal Fanfold, 8 1/2 x 13 in.
          ppsUser         -->DMPAPER_USER	User-defined

    27. PrintHeightԶֽŵĳ,ԺΪλ
 
    28. PrintWidthԶֽŵĿ,ԺΪλ

    29. PrintVisible:  ǷӡVisible=FalseĿؼԷƱ״;
        ֵ       
        =========================
        True     ӡ
        False    ӡ

    30. PrnEmpty:DBGridǷÿָĴӡΪBoolean
        ֵ       
        =============================
        True     Ҫÿ
        False    ÿ

    31. RecordPerPage: DBGridÿҳӡΪ0Զ㣬򰴴ӡμPrintReport

    32. TitleTitleı⡣ͬɴͱμBottomTitle

    33. TitleTitleFont塣

    34. TopMarginֽϲĿհףԺΪλ

    35. TotalSum: ǷDBGridֵֶνԶܺϼơΪBoolean
        ֵ       
        =========================
        True     Զ㲢һҳӡܺϼ
        False    ӡܺϼ

    36. TotalSumLabel: ܺϼеı⡣ȱʡΪܺϼơ޸ġ

    37. HMiddle: ӡǷֱСΪBooleanFitPageHeightΪTrueʱЧ
        ֵ       
        ========================
        True     ֱ
        False    

ġ
    1. procedure PrintReport;
       : ôӡؼԭPrinterView(p1,p2)еĲp1,p2Ļӡʱʧȥ壬
                ãԻƱʱp1ãΪ˱ǰ汾ļݣ˷
               
                Ļӡʱ뾡PrintReport, PrinterViewԻƱʱʹá

     ԻƱӡĻʹá

    2. function PrinterView(const pCount,recCount:Integer):Boolean;
       : ôӡؼ
       pCount:  ҳ,Ϊ0ʱ,recCount,ڲOnPaint¼ʱû.
             recCount:ָDBGridÿҳӡļ¼

    3. procedure PainInit(Canvas,PageNumber);
       : ڴOnPaint¼ʱʼӡ,˺ڻǰ.
       : ֻΪCanvasPageNumber,;

塢¼
   
   1.
    procedure <Form>.<ؼ>Paint(Canvas: TPreviewCanvas; PageNumber : LongInt);
    ӡ¼ڳƴӡ,˴¼,ô¼Ĵԭ
              Ļӡ
    Canvas     -->ԱԼĴӡCanvas,ΪTPreviewCanvas
          PageNumber -->ǰӡҳţΪLongInt

    TPreviewCanvasʹõĴӡ£ǵʹοTCanvas.
      1. procedure Rectangle( x, y, x2, y2 : integer );
      2. procedure RoundRect( x1, y1, x2, y2, x3, y3 : integer );
      3. procedure TextOut( x, y : integer; const text : string );
      4. procedure TextRect( Rect : TRect; X, Y : Longint; const Text : string );
      5. procedure FloodFill( X,Y : Longint; Color : TColor; FillStyle : TFillStyle );
      6. procedure StretchDraw( const rect : TRect; Graphic : TGraphic );
      7. function TextHeight( const text : string ) : Longint;
      8. function TextWidth( const text : string ) : Longint;
      9. procedure FillRect( const rect : TRect );
      10.procedure MoveTo( x, y : longint );
      11.procedure LineTo( x, y : longint );
      12.procedure SetFont( font : TFont );
      13.procedure Arc( x1, y1, x2, y2, x3, y3, x4, y4 : integer );
      14.procedure BrushCopy( const dest : TRect; Bitmap : TBitmap;
           const Source : TRect; Color : TColor );
      15.procedure Chord( x1, y1, x2, y2, x3, y3, x4, y4 : integer );
      16.procedure FrameRect( rect : TRect );
      17.procedure MoveTo( x, y : longint );
      18.procedure LineTo( x, y : longint );


    ӣ
    procedure TForm1.Preview1Paint(Canvas: TPreviewCanvas; PageNumber : LongInt);
    var
    Font : TFont;
    rect : TRect;
    val  : string;
    begin
      if PageNumber = 1 then
        begin

        Preview1.PainInit(Canvas,PageNumber);

        Canvas.font.size:=12;
        rect.left:=PixelsToTwips(1,canvas);
        rect.top:=PixelsToTwips(1,canvas);
        Canvas.Textout( rect.left, rect.top, 'Printpӡ' );

        rect.left:=PixelsToTwips(2,canvas);
        rect.top:=PixelsToTwips(PointsToPixels(12),canvas);
        Canvas.Textout( rect.left, rect.top, 'Printpӡ');

        rect.top := 0;
        rect.left := Canvas.TextWidth('The');
        rect.bottom := Canvas.TextHeight( 'Printpӡ' ) + 200;
        rect.right := rect.left + Canvas.TextWidth( 'Printpӡ' ) + 200;
        Canvas.Brush.Color := clBlack;
        Canvas.FillRect( rect );

        Canvas.Font.Color := clWhite;
        Canvas.Textout( rect.left + 100, 100, 'Printpӡ' );

        Canvas.Brush.Color := clWhite;
        Canvas.Font.Color := clBlack;
        Canvas.Font.Size := 12;

        rect.left := Canvas.TwipMaxX - Canvas.TextWidth('Newsletter Number')
           - Canvas.TextWidth( '***00/00/00' ) - 100;

        Canvas.TextOut( rect.left, 100, 'Printpӡ' );

        rect.top := 200+Canvas.textheight('N');
        val := '1';
        Canvas.TextOut( Canvas.TwipMaxX - 100 - Canvas.TextWidth(val), 100,
                        val );

        val := FormatDateTime( 'dd/mm/yy', Now );
        Canvas.TextOut( rect.left, rect.top, 'ڲ' );
        Canvas.TextOut( Canvas.TwipMaxX - 100 - Canvas.TextWidth(val),
                        rect.top, val );

        rect.top := rect.bottom + 600;
        Canvas.Font.Size := 12;
        val := 'This week''s new releases... 20% OFF TO CARD HOLDERS for the first month of release';
        rect.left := (Canvas.TwipMaxX - Canvas.TextWidth(val)) div 2;
        Canvas.TextOut( rect.left, rect.top, val );
        Canvas.Font.Style := [];

        rect.bottom := rect.top + Canvas.TextHeight( 'W' ) + 100;
        rect.top := 20;
        rect.left := 20;
        rect.right := Canvas.TwipMaxX - 20;
        Canvas.Brush.Color := clBlack;
        Canvas.FrameRect( rect );
        Canvas.Brush.Color := clWhite;
        end
     else
        begin
        Canvas.Font.Size := 36;
        Canvas.Textout( 1440, 1440, 'ӡ' );
        Canvas.Font.Size := 36;
        Canvas.TextOut( 4*1440, 20, 'Page Number :'+inttostr( PageNumber ) );
        end;
    end;

  2.
   procedure <Form>.<ؼ>CustomControl(Canvas: TPreviewCanvas;  vCtrl: TControl; Rect: myTRect);

   Զؼ¼ScreenReportֵ֧ĵؼʱ¼vCtrlΪ˿ؼ
бƴ˿ؼĴӡ롣ȻҪScreenReportĻCanvasRectС
   myTRectTRect÷ֻͬmyRectеԪLongInt͡CanvasʹõĻͼͬϡעЩ
Ļͼλtwipsص!

Զؼӣ

procedure TForm1.Preview1CustomControl(Canvas: TPreviewCanvas;vCtrl: TControl; Rect: myTRect);
  var
    str1:string;
begin
    if vCtrl is TxxLabel then {Labelؼ}
    begin
      {ӡؼݣκͼζԭؼʾʽ}
       Canvas.SetFont((vCtrl as TxxLabel).Font);
       str1:=(vCtrl as TxxLabel).Caption;
       Canvas.TextOut(rect.left,rect.top,str1);
    end;
end;
    
    㵱ȻҲԽ¼ڻƱʱȡÿȨmyRectķΧԱĻơ
    һ㲻ʹá



  ο..\Demo\Demo.DPR

ߡ
    
    ҪӡShapeʹScreenReportTArtShapeؼDelphiShape
    ʹSystemĿؼԤʱ岻š
    ĳЩܻϸ΢

ˡScreenReportѯˣ뷢e-mail:

21th@public.km.yn.cn

