在好例子网,分享、交流、成长!
您当前所在位置:首页Pascal 开发实例Delphi数据库编程 → KingReport报表控件

KingReport报表控件

Delphi数据库编程

下载此实例
  • 开发语言:Pascal
  • 实例大小:5.21M
  • 下载次数:19
  • 浏览次数:214
  • 发布时间:2022-05-19
  • 实例类别:Delphi数据库编程
  • 发 布 人:lfwlfw
  • 文件格式:.zip
  • 所需积分:2
 相关标签: KingReport报表控件

实例介绍

【实例简介】KingReport报表控件

目  录


KingReport

本套组件是一套简洁实用的报表组件,设计结构合理,可扩充的余地很大,为作者一年前所作,限于当时的水平,所以可能有不合理之处!现在公开以源码以供Delphi同仁学习研究之用,且勿用于商业用途! 如用于商业用途需证得作者同意!( yking29@sina.com

1.1 ReportMaster

1.1.1 说明

首先利用报表模板设计工具(在 .\Tools” 目录里面有Demo),设计模板,如下图所示:


 


'列名称'是指让用户在报表中看到的表头当中的字段名称, '列内容'是指在数据库中对应的字段的名称, '数值否'内只能填写'T''F'用来表示此字段是否可以当作数值类型。

在填写完毕以后,按“确认”按钮,弹出“报表页面设计的窗体”如下:

 

然后可以通过“新建主列”来增加报表的表头列数,也可以通过新建子列来产生复合表头,当然表头显示的内容也可以在此窗体的“列名称”中自行修改,最后设计可以设计“外观参数”、“页眉页角”等其他参数,设计完毕以后,按“确认”按钮,出现如下报表:

 

最后,点击“ 保存”按钮保存为报表模板。

 

最后报表的使用当中(在 .\Samples\报表” 目录里面有Demo),本控件只需要链接一个DataSet,如下图:

从头到尾依次把数据显示出来,最终的用户只能设计报表的页面参数而不能设计报表的字段。所有页面参数得设计都在者“报表设计”的一个窗体内实现,当报表为100%比例显示的时候,用户可以通过拖拽表格线来实现列宽的调整,所见既所得。

此外其他属性如下:

ReportControl属性当中,可以把实现“上一页”“下一页”等功能的按钮对应到现成的ToolButton当中,就是说,为了实现“上一页”“下一页”等功能,这个控件的使用者不需要写任何代码,只要在相应的属性中对应上ToolButton按钮即可,点击相应的ToolButton就有了这样的功能!

ReportLayourReportPrinter属性为报表得页面设计和打印机设置得属性。

 

1.1.2 单元声明

unit ReportMaster;

 

interface

 

uses

  Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms, Dialogs, Registry,

  Db, Printers, WinSpool, ComCtrls, Variants, ComObj, QClipbrd, StdCtrls, Buttons,

  Menus, ReportDesign, ReportFunc;

 

const

  { Horz Align }

  ALIGN_LEFT = 0;

  ALIGN_HCENTER = 1;

  ALIGN_RIGHT = 2;

 

  { Vert Align }

  ALIGN_TOP = 0;

  ALIGN_VCENTER = 1;

  ALIGN_BOTTOM = 2;

 

  {Mix Cell Height}

  CELLMINHEIGHT = 16;

 

  { 斜线定义}

  LINE_LEFT1 = 1; { Left Top to Right Bottom }

  LINE_LEFT2 = 2; { Left Top to Right        }

  LINE_LEFT3 = 4; { Left Top to Bottom       }

 

  LINE_RIGHT1 = $100; { Right Top to Left Bottom }

  LINE_RIGHT2 = $200; { Right Top to Left        }

  LINE_RIGHT3 = $400; { Right Top to Bottom      }

 

  {常用的打印纸张类型 53种}

  DMPAPER_LETTER         = 1;   { Letter 8 12 x 11 in             }

  DMPAPER_LETTERSMALL    = 2;   { Letter Small 8 12 x 11 in       }

  DMPAPER_TABLOID        = 3;   { Tabloid 11 x 17 in              }

  DMPAPER_LEDGER         = 4;   { Ledger 17 x 11 in               }

  DMPAPER_LEGAL          = 5;   { Legal 8 12 x 14 in              }

  DMPAPER_STATEMENT      = 6;   { Statement 5 12 x 8 12 in        }

  DMPAPER_EXECUTIVE      = 7;   { Executive 7 14 x 10 12 in       }

  DMPAPER_A3             = 8;   { A3 297 x 420 mm                 }

  DMPAPER_A4             = 9;   { A4 210 x 297 mm                 }

  DMPAPER_A4SMALL        = 10;  { A4 Small 210 x 297 mm           }

  DMPAPER_A5             = 11;  { A5 148 x 210 mm                 }

  DMPAPER_B4             = 12;  { B4 (JIS) 250 x 354              }

  DMPAPER_B5             = 13;  { B5 (JIS) 182 x 257 mm           }

  DMPAPER_FOLIO          = 14;  { Folio 8 12 x 13 in              }

  DMPAPER_QUARTO         = 15;  { Quarto 215 x 275 mm             }

  DMPAPER_10X14          = 16;  { 10x14 in                        }

  DMPAPER_11X17          = 17;  { 11x17 in                        }

  DMPAPER_NOTE           = 18;  { Note 8 12 x 11 in               }

  DMPAPER_ENV_9          = 19;  { Envelope #9 3 78 x 8 78         }

  DMPAPER_ENV_10         = 20;  { Envelope #10 4 18 x 9 12        }

  DMPAPER_ENV_11         = 21;  { Envelope #11 4 12 x 10 38       }

  DMPAPER_ENV_12         = 22;  { Envelope #12 4 \276 x 11        }

  DMPAPER_ENV_14         = 23;  { Envelope #14 5 x 11 12          }

  DMPAPER_ENV_DL         = 27;  { Envelope DL 110 x 220mm         }

  DMPAPER_ENV_C5         = 28;  { Envelope C5 162 x 229 mm        }

  DMPAPER_ENV_C3         = 29;  { Envelope C3  324 x 458 mm       }

  DMPAPER_ENV_C4         = 30;  { Envelope C4  229 x 324 mm       }

  DMPAPER_ENV_C6         = 31;  { Envelope C6  114 x 162 mm       }

  DMPAPER_ENV_C65        = 32;  { Envelope C65 114 x 229 mm       }

  DMPAPER_ENV_B4         = 33;  { Envelope B4  250 x 353 mm       }

  DMPAPER_ENV_B5         = 34;  { Envelope B5  176 x 250 mm       }

  DMPAPER_ENV_B6         = 35;  { Envelope B6  176 x 125 mm       }

 

  DMPAPER_9X11           = 44;  { 9 x 11 in                       }

  DMPAPER_10X11          = 45;  { 10 x 11 in                      }

  DMPAPER_15X11          = 46;  { 15 x 11 in                      }

  DMPAPER_LETTER_EXTRA   = 50;  { Letter Extra 9 \275 x 12 in     }

  DMPAPER_LEGAL_EXTRA    = 51;  { Legal Extra 9 \275 x 15 in      }

  DMPAPER_TABLOID_EXTRA  = 52;  { Tabloid Extra 11.69 x 18 in     }

  DMPAPER_A4_EXTRA       = 53;  { A4 Extra 9.27 x 12.69 in        }

  DMPAPER_A4_TRANSVERSE  = 55;  { A4 Transverse 210 x 297 mm      }

  DMPAPER_A5_TRANSVERSE  = 61;  { A5 Transverse 148 x 210 mm      }

  DMPAPER_B5_TRANSVERSE  = 62;  { B5 (JIS) Transverse 182 x 257 mm}

  DMPAPER_A3_TRANSVERSE  = 67;  { A3 Transverse 297 x 420 mm      }

  DMPAPER_PENV_1         = 96;  { PRC Envelope #1 102 x 165 mm    }

  DMPAPER_PENV_2         = 97;  { PRC Envelope #2 102 x 176 mm    }

  DMPAPER_PENV_3         = 98;  { PRC Envelope #3 125 x 176 mm    }

  DMPAPER_PENV_4         = 99;  { PRC Envelope #4 110 x 208 mm    }

  DMPAPER_PENV_5         = 100; { PRC Envelope #5 110 x 220 mm    }

  DMPAPER_PENV_6         = 101; { PRC Envelope #6 120 x 230 mm    }

  DMPAPER_PENV_7         = 102; { PRC Envelope #7 160 x 230 mm    }

  DMPAPER_PENV_8         = 103; { PRC Envelope #8 120 x 309 mm    }

  DMPAPER_PENV_9         = 104; { PRC Envelope #9 229 x 324 mm    }

  DMPAPER_PENV_10        = 105; { PRC Envelope #10 324 x 458 mm   }

 

  { 打印机抖动模式}

  DMDITHER_NONE      = 1;     { 不抖动  }

  DMDITHER_COARSE    = 2;     { 粗糙画笔模式  }

  DMDITHER_FINE      = 3;     { 优秀画笔模式  }

  DMDITHER_LINEART   = 4;     { 艺术抖动模式  }

  DMDITHER_GRAYSCALE = 10;    { 灰度抖动模式  }

 

  { 打印机双工模式 }

  DMDUP_SIMPLEX    = 1;       { 简单双工模式 }

  DMDUP_VERTICAL   = 2;       { 纵向双工模式 }

  DMDUP_HORIZONTAL = 3;       { 横向双工模式 }

 

  { 打印机的色彩模式 }

  DMCOLOR_MONOCHROME = 1;     { 单色模式 }

  DMCOLOR_COLOR = 2;          { 彩色模式 }

 

  { 打印机打印品质 }

  DMRES_DRAFT = LongWord(-1);   { 草图 }

  DMRES_LOW = LongWord(-2);     { 一般 }

  DMRES_MEDIUM = LongWord(-3);  { 中等 }

  DMRES_HIGH = LongWord(-4);    { 优秀 }

 

 

  {Excel相对应的一部分纸张}

  xlPaperLetter       = $00000001;

  xlPaperLetterSmall  = $00000002;

  xlPaperTabloid      = $00000003;

  xlPaperLedger       = $00000004;

  xlPaperLegal        = $00000005;

  xlPaperStatement    = $00000006;

  xlPaperA3           = $00000008;

  xlPaperA4           = $00000009;

  xlPaperA4Small      = $0000000A;

  xlPaperA5           = $0000000B;

  xlPaperB4           = $0000000C;

  xlPaperB5           = $0000000D;

  xlPaperFolio        = $0000000E;

  xlPaperQuarto       = $0000000F;

  xlPaper10x14        = $00000010;

  xlPaper11x17        = $00000011;

  xlPaperNote         = $00000012;

  xlPaperEnvelope9    = $00000013;

  xlPaperEnvelope10   = $00000014;

  xlPaperEnvelope11   = $00000015;

  xlPaperEnvelope12   = $00000016;

  xlPaperEnvelope14   = $00000017;

  xlPaperEnvelopeDL   = $0000001B;

  xlPaperEnvelopeC5   = $0000001C;

  xlPaperEnvelopeC3   = $0000001D;

  xlPaperEnvelopeC4   = $0000001E;

  xlPaperEnvelopeC6   = $0000001F;

  xlPaperEnvelopeC65  = $00000020;

  xlPaperEnvelopeB4   = $00000021;

  xlPaperEnvelopeB5   = $00000022;

  xlPaperEnvelopeB6   = $00000023;

 

  {Excle打印纸张方向}

  xlLandscape = $00000002; //横向

  xlPortrait  = $00000001;  //纵向

 

  {Excle线型}

  xlMedium     = $FFFFEFD6;

  xlThick      = $00000004;

  xlThin       = $00000002;

  xlContinuous = $00000001;

 

  {Excel的对齐方式}

  xlCenter = $FFFFEFF4;

  xlLeft   = $FFFFEFDD;

  xlRight  = $FFFFEFC8;

  xlTop    = $FFFFEFC0;

  xlBottom = $FFFFEFF5;

 

  {默认打印机分辨率}

  DEFAULT_PRINTER_PPI = 360;

 

type

  TReportCell = class;

  TReportLine = class;

  TTLogoBmp = class;

  TReportMaster = class;

  TReportLayout = class;

  TReportPrinter = class;

 

  PPalEntriesArray = ^TPalEntriesArray; {for palette re-construction}

  TPalEntriesArray = array[0..0] of TPaletteEntry;

  TIntegerArray = array of Integer;

 

  {打印机参数}

  TMyOrientation = (knPortrait, knLandscape);

  TMyColorType = (knColor, knMonochrome);

  TMyDuplexType = (knSimplex, knHorzDuplex, knVertDuplex);

  TMyDitherType = (knNone, knCourse, knFine, knLineArt, knGrayScale);

  TMyPrintQuality = (knDraft, knLow, knMedium, knHigh);

 

  {预览参数}

  TMyViewState= (knHundred, knWidth, knHeight);

 

  TSelectEvent = procedure(HereText: string; Button: TMouseButton; X, Y: Integer) of object;

  TPreparingEvent = procedure(var InNo, OutNo: Integer; var IOText: string) of object;

  {----------------------------------------------------------------------------}

 

  TControls = class(TPersistent)

  private

    FReportMaster: TReportMaster;

    FCurPage: Integer;

 

    FFirstPage: TToolButton;

    FPrevPage:  TToolButton;

    FNextPage:  TToolButton;

    FLastpage:  TToolButton;

 

    FProgressBar: TProgressBar;

    //FProgressRect: TRect;

    //FProgressPanel: TStatusPanel;

 

    FPageNO: TEdit;

    FPageCount: TCustomLabel;

 

    FZoomScale: TComboBox;

 

    procedure ZoomScaleChange(Sender: TObject);

 

    procedure FirstPageClick(Sender: TObject);

    procedure PrevPageClick(Sender: TObject);

    procedure NextPageClick(Sender: TObject);

    procedure LastpageClick(Sender: TObject);

 

    procedure MyEdtKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

 

    //procedure ProcessDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);

  protected

    procedure SetLabel(Value: TCustomLabel);

    procedure SetEdit(Value: TEdit);

    procedure SetComboBox(Value: TComboBox);

    procedure SetProgressBar(Value: TProgressBar);

    procedure SetButton(Index: Integer; Value: TToolButton);

  public

    constructor Create(AOwner: TReportMaster);

  published

    property FirstPage: TToolButton index 0 read FFirstPage write SetButton;

    property PrevPage:  TToolButton index 1 read FPrevPage  write SetButton;

    property NextPage:  TToolButton index 2 read FNextPage  write SetButton;

    property Lastpage:  TToolButton index 3 read FLastpage  write SetButton;

 

    property PageNO   : TEdit  read FPageNo    write SetEdit;

    property PageCount: TCustomLabel read FPageCount write SetLabel;

 

    Property ZoomScale: TComboBox  read FZoomScale write SetComboBox;

    property ProgressBar: TProgressBar read FProgressBar write SetProgressBar;

  end;

 

  {-------------------------------------------------------------------------------}

  TExcelExport = Class(TObject)

  private

    FExcelApp: Variant;       //Excel的Application

    FReportMaster: TReportMaster;

    FFieldLineCount: Integer; //表头一共有多少行

    FWorkSheetNO: Integer;    //第几个WorkSheet

 

    function GetRowsFlag(Num: Integer): string; //得到行标志

    function GerCellSection(SRow, SColumn, ERow, EColumn: Integer): Variant; //选中某一区域

    procedure ExcelMergeCells(SRow, SColumn, ERow, EColumn: Integer); //合并某一选中区域

    procedure ExcelColumnWidth; //设置列宽

    procedure ExcleTitleArea;   //表头区域内容

    procedure ExcelTitleBar;    //设置页头部分的

    procedure FillDataToExcel;  //向Excel填充数据

    procedure ExcleDataArea;    //数据区域内容

    procedure ExclePageSetup;   //设置Excel打印纸张

    procedure ExclePageSize;    //设置Excel打印参数

  public

    constructor Create(AOwner: TReportMaster);

    destructor Destroy; override;

    procedure ExportExcel;      //输出Excel

  end;

 

 

  {-------------------------------------------------------------------------------}

  TReportCell = class(TObject)

  private

    FIsNum: Boolean;   //是否是数字

    FDecimal: Integer; //小数点位数

    FKiloFmt: Boolean; //千分位显示

 

    FLeftMargin: Integer;    // 左边的空格

    FOwnerLine: TReportLine; // 隶属行

 

    {隶属和覆盖的单元格仅限于纵向,因为只有纵向的覆盖在高度上才会引起不同}

    FOwnerCell: TReportCell; // 隶属的单元格

    FCellsList: TList;       // 覆盖的Cell,在FCellsList中存放TReportCell

 

    {Index}

    FCellIndex: Integer; // Cell在行中的索引

 

    {size & position}

    FCellLeft: Integer;

    FCellWidth: Integer;

 

    FCellRect: TRect; // 计算得来

    FTextRect: TRect;

 

    FDragCellHeight: Integer;

    FMinCellHeight: Integer;

    FRequiredCellHeight: Integer;

 

    {Border}

    FLeftLine: Boolean;

    FLeftLineWidth: Integer;

 

    FTopLine: Boolean;

    FTopLineWidth: Integer;

 

    FRightLine: Boolean;

    FRightLineWidth: Integer;

 

    FBottomLine: Boolean;

    FBottomLineWidth: Integer;

 

    {斜线}

    FDiagonal: UINT;

 

    {Color}

    FTextColor: COLORREF;

    FBackGroundColor: COLORREF;

 

    FTopLineColor: COLORREF;

    FBottomLineColor: COLORREF;

    FLeftLineColor: COLORREF;

    FRightLineColor: COLORREF;

 

    {Align}

    FHorzAlign: Integer;

    FVertAlign: Integer;

 

    {string}

    FCellText: string;

 

    {Font}

    FLogFont: TLOGFONT;

    function GetCellHeight: Integer;

    function GetCellTop: Integer;

    function GetOwnerLineHeight: Integer;

  protected

    procedure SetLeftMargin(LeftMargin: Integer);

 

    procedure SetOwnerLine(OwnerLine: TReportLine);

    procedure SetOwnerCell(Cell: TReportCell);

    function GetOwnedCellCount: Integer;

 

    procedure SetCellLeft(CellLeft: Integer);

    procedure SetCellWidth(CellWidth: Integer);

 

    procedure SetLeftLine(LeftLine: Boolean);

    procedure SetLeftLineWidth(LeftLineWidth: Integer);

 

    procedure SetTopLine(TopLine: Boolean);

    procedure SetTopLineWidth(TopLineWidth: Integer);

 

    procedure SetRightLine(RightLine: Boolean);

    procedure SetRightLineWidth(RightLineWidth: Integer);

 

    procedure SetBottomLine(BottomLine: Boolean);

    procedure SetBottomLineWidth(BottomLineWidth: Integer);

 

    procedure SetCellText(CellText: string);

    procedure SetLogFont(NewFont: TLOGFONT);

 

    procedure SetBackGroundColor(BkColor: COLORREF);

    procedure SetTextColor(TextColor: COLORREF);

 

  public

    constructor Create;

    destructor Destroy; override;

 

    procedure AddOwnedCell(Cell: TReportCell);

    procedure RemoveAllOwnedCell;

    procedure RemoveOwnedCell(Cell: TReportCell);

    function IsCellOwned(Cell: TReportCell): Boolean;

    procedure CalcCellRect;

    procedure CalcMinCellHeight;

    procedure PaintCell(hPaintDC: HDC; bPrint: Boolean); overload;

    procedure PaintCell(hPaintDC: HDC); overload;

    procedure CopyCell(Cell: TReportCell; bInsert: Boolean);

 

    {DisplayFormat}

    property IsNum: Boolean read FIsNum write FIsNum;

    property Decimal: Integer read FDecimal write FDecimal;

    property KiloFmt: Boolean read FKiloFmt write FKiloFmt;

 

    {Properties}

    property LeftMargin: Integer read FLeftMargin write SetLeftMargin;

    property OwnerLine: TReportLine read FOwnerLine write SetOwnerLine;

    property OwnerCell: TReportCell read FOwnerCell write SetOwnerCell;

    property OwnedCellCount: Integer read GetOwnedCellCount;

 

    property CellIndex: Integer read FCellIndex write FCellIndex;

 

    {size & position}

    property CellLeft: Integer read FCellLeft write SetCellLeft;

    property CellWidth: Integer read FCellWidth write SetCellWidth;

    property CellTop: Integer read GetCellTop;

    property CellHeight: Integer read GetCellHeight;

 

    property CellRect: TRect read FCellRect;

    property TextRect: TRect read FTextRect;

 

    property DragCellHeight: Integer read FDragCellHeight;

    property MinCellHeight: Integer read FMinCellHeight;

    property RequiredCellHeight: Integer read FRequiredCellHeight;

    property OwnerLineHeight: Integer read GetOwnerLineHeight;

 

    {Border}

    property LeftLine: Boolean read FLeftLine write SetLeftLine default True;

    property LeftLineWidth: Integer read FLeftLineWidth write SetLeftLineWidth default 1;

 

    property TopLine: Boolean read FTopLine write SetTopLine default True;

    property TopLineWidth: Integer read FTopLineWidth write SetTopLineWidth default 1;

 

    property RightLine: Boolean read FRightLine write SetRightLine default True;

    property RightLineWidth: Integer read FRightLineWidth write SetRightLineWidth default 1;

 

    property BottomLine: Boolean read FBottomLine write SetBottomLine default True;

    property BottomLineWidth: Integer read FBottomLineWidth write SetBottomLineWidth default 1;

 

    {斜线}

    property Diagonal: UINT read FDiagonal write FDiagonal;

 

    {Color}

    property TextColor: COLORREF read FTextColor write SetTextColor default clBlack;

    property BkColor: COLORREF read FBackGroundColor write SetBackGroundColor default clWhite;

 

    property TopLineColor: COLORREF read FTopLineColor write FTopLineColor default clBlack;

    property BottomLineColor: COLORREF read FBottomLineColor write FBottomLineColor default clBlack;

    property LeftLineColor: COLORREF read FLeftLineColor write FLeftLineColor default clBlack;

    property RightLineColor: COLORREF read FRightLineColor write FRightLineColor default clBlack;

 

    {Align}

    property HorzAlign: Integer read FHorzAlign write FHorzAlign default 1;

    property VertAlign: Integer read FVertAlign write FVertAlign default 1;

 

    {string}

    property CellText: string read FCellText write SetCellText;

 

    {Font}

    property LogFont: TLOGFONT read FLogFont write SetLogFont;

  end;

 

  {----------------------------------------------------------------------------}

  TReportLine = class(TObject)

  private

    FReportMaster: TReportMaster;

    FCells: TList;                // 保存所有在该行中的CELL

    FLineIndex: Integer;          // 行的索引

 

    FMinHeight: Integer;

    FDragHeight: Integer;

    FLineTop: Integer;

    FLineRect: TRect;

    FAdjustHeight: Integer;   //2002.12.15

 

    function GetLineHeight: Integer;

    function GetLineRect: TRect;

 

    procedure SetDragHeight(Value: Integer);

    procedure SetLineTop(Value: Integer);

 

    //function GetAdjustHeight: Integer;  //2002.12.15

    //procedure SetAdjustHeight(Value: Integer);    //2002.12.15

  protected

    { Protected declarations }

  public

    procedure CalcLineHeight;

    procedure CreateLine(LineLeft, CellNumber, PageWidth: Integer);

    procedure CopyLine(Line: TReportLine; bInsert: Boolean);

 

    constructor Create(AOwner: TReportMaster);  //Modified 2002.12.15

    destructor Destroy; override;

 

    property LineIndex: Integer read FLineIndex write FLineIndex;

    property LineHeight: Integer read GetLineHeight write SetDragHeight;

    property LineTop: Integer read FLineTop write SetLineTop;

    property LineRect: TRect read GetLineRect;

    property PrevLineRect: TRect read FLineRect;

 

    //Delete 2002.12.15

    //property ReportMaster: TReportMaster read FReportMaster write FReportMaster;

    //property AdjustHeight: Integer read GetAdjustHeight write SetAdjustHeight;

  end;

 

  {----------------------------------------------------------------------------}

  TReportMaster = class(TWinControl)

  private

    FAppDir: string;    //Application的Dir

    FDataSet: TDataSet; //报表数据来源

 

    FLineList: TList;    //保存当前显示页的信息

    FPrintList: TList;   //保存要打印的某一页的信息

    FTempletList: TList; //保存模板的信息

    FSumList: TList;     //保存汇总内容的链表

    FVarList: TList;     //保存变量的名字和值的对照表

    FNodeList: TList;    //保存节点信息

    FResultList: TList;  //保存报表显示结果链表的链表   // Add 2002.12.5

 

    FSelectCells: TList; //存放选中Cell的链表

    FEditCell: TReportCell; {Friend VCL}

 

    FLogoBmp: TTLogoBmp; //存放徽标的类  Add 2002.12.15

    FAdjustLineHeight: Integer; //行高的调整系数(单位:象素)  Add 2002.12.15

 

    FTempletHeaderList: TList;   //模板页眉 存 TReportCell

    FTempletFooterList: TList;   //模板页脚 存 TReportCell

 

    FLineHeaderList: TList;      //当前显示的页眉

    FLineFooterList: TList;      //当前显示的页脚

 

    FPrintHeaderList: TList;     //打印或者导出Excel的时候用到的页眉页脚数据

    FPrintFooterList: TList;

 

    FFieldItemList: TList;        //设计模板用用来存放TNodeParam类型的联表

    FPopupMenu: TPopupMenu;       //控件的右键菜单

    FDesignPopupMenu: TPopupMenu; //控件在设计模板的时候在Memo当中的右键变量菜单

 

    FHeaderLine: Boolean; //是否现实页眉分隔线

    FFooterLine: Boolean; //是否现实页脚分隔线

 

    FLineCount: Integer;      //共有多少行Line

 

    FOldPageWidth, FOldPageHeight: Integer; //保存上一次页面大小设置后的纸张大小

    FAdaptFontSize: Boolean;                //纸张类型改变变大后是否相应变大字体 (默认为改变 True)

    FReadOnly: Boolean;                     //报表是否允许编辑

 

    {是否学习版本?}

    FStudyEdition: Boolean;

 

    {显示、打印参数相关...}

    FPrinter: TReportPrinter;     //打印机Class

    FPaperName: string;           //当前纸张类型名称 从打印机Class获得

    FOrientation: TMyOrientation; //纸张进纸方向 也从打印机Calss获得

    FIsDisHorLine: Boolean;       //内容区域网格是否显示横线

    FIsDisVerLine: Boolean;       //内容区域网格是否显示竖线

    FIsDisPageSum: Boolean;       //是否显示本业小计

    FIsBorderFrame: Boolean;      //是否加粗边框

    FAutoRefresh: Boolean;        //是否自动刷新

    FReportScale: Integer;        //显示比例

    FSumTitlePosition: Integer;   //汇总标题的位置 (下标从1开始)

    FIsSumDrawDiagonal: Boolean;  //在汇总行单中 无内容的部分是不是画斜线

 

    FViewState: TMyViewState;

    FPageWidth: Integer;   //纸张宽度

    FPageHeight: Integer;  //纸张高度

 

    FLayout: TReportLayout;     //页面设置Calss 统领ReportMaster类的页面设置内容

    FControls: TControls;       //对应控制按钮的类

    FExcelExport: TExcelExport; //把报表数据导出Excel的类

 

    FLeftMargin: Integer;       //边距  (单位:象素)

    FRightMargin: Integer;

    FTopMargin: Integer;

    FBottomMargin: Integer;

 

    FLeftMargin1: Integer;      //边距  (单位:mm)

    FRightMargin1: Integer;

    FTopMargin1: Integer;

    FBottomMargin1: Integer;

 

    {鼠标操作支持}

    FMousePoint: TPoint;

    FDragState: Boolean;

 

    {编辑、颜色及字体}

    FEditWnd: HWND;            //当前正在编辑的Cell的Edti的Handle

    FEditBrush: HBRUSH;        //当前正在编辑的Cell的Edti的Brush

    FEditFont: HFONT;          //当前正在编辑的Cell的Edti的HFont

 

    {报表计算相关的变量...}

    FPageCount: Integer; // page count

    FCurPageNo: Integer;

 

    FOnSelected: TSelectEvent;

    FOnPreparing: TPreparingEvent;

 

    FReportStyle: Byte;          //生成报表的风格 0:普通报表  1:特殊清单  2:项目编码  5:固定格式表格  (3,4为预留的)

    FIntArrayList: TStringList;  //把整数数组作为StringList存放的联表

  protected

    procedure CreateWnd; override;

    procedure BateEdition(hPaintDC: HDC);

 

    {Windows消息相关...}

    procedure WMPaint(var Message: TMessage); message WM_PAINT;

    procedure WMLButtonUp(var Message: TMessage); message WM_LBUTTONUP;

    procedure WMLButtonDown(var Message: TMessage); message WM_LBUTTONDOWN;

    procedure WMRButtonDown(var Message: TMessage); message WM_RBUTTONDOWN;

    procedure WMLButtonDBLClk(var Message: TMessage); message WM_LBUTTONDBLCLK;

    procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE;

    procedure WMContextMenu(var Message: TMessage); message WM_CONTEXTMENU;

    procedure WMCOMMAND(var Message: TMessage); message WM_COMMAND;

    procedure WMCTLColor(var Message: TMessage); message WM_CTLCOLOREDIT;

    procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;

 

    {WMLButtonDown消息触发的过程...}

    procedure SwithViewScale;                                        //来回切换比例模式

    procedure StartMouseDrag(point: TPoint);                         //在WMLButtonDown消息当中触发的鼠标拖拽的操作

    procedure StartMouseSelect(point: TPoint; bSelectFlag: Boolean); //在WMLButtonDown触发的鼠标选择的操作

    procedure MouseMoveSeriesSelect(message: TMSG);                  //在WMMouseMove当中触发的连续选中Cell的操作

 

    {Window size}

    procedure CalcWndSize(Flag: Boolean);                            //控件大小变化的过程 Flag为True表示真变化 为False表示只是比例变化

    procedure RegulateThirdLine(IsTemplet: Boolean); //Add 2002.11.6 //因控件大小的变化引起表头行的误差,这个过程为修正误差的操作

    procedure UpdateLineSize(IsTemplet: Boolean);                    //报表内容自动伸缩的过程

 

    {链表操作相关...}

    procedure CopyReportLineList(var DestList, SourceList: TList; IsFull: Boolean);

    procedure CopyToPrintList;

    procedure CopyToTempletList;

    procedure CopyToLineList;

 

    {页眉页脚、表头相关...}

    procedure CreateHeaderList;

    procedure CreateFooterList;

 

    procedure SetHFText(Index: Integer; Value: string); // Index 为0为页眉  1为页脚

    Procedure SetTitleText(Index: Integer; Value: string);

    Procedure SetHFLine(Index: Integer; Value: Boolean);

 

    function GetHFText(Index: Integer): string;

    function GetTitleText(Index: Integer): string;

    procedure AnalyzeTitle(var Title: string; var StrList: TStringList);

    procedure UpdateHeaderFooterSize;                  //更新页眉页脚尺寸

    procedure UpdateHeaderFooterText(IsView: Boolean); //更新页眉页脚内容 IsView是看得见的 还是看不见的

 

    procedure ReadHeaderFooter(IsHeader: Boolean; var TargetStream: TMemoryStream);

    procedure WriteHeaderFooter(IsHeader: Boolean; var TargetStream: TMemoryStream);

 

 

    {报表字段相关...}

    procedure ReadFieldItems(var TargetStream: TMemoryStream);    //Add 2002.12.15

    procedure WriteFieldItems(var TargetStream: TMemoryStream);   //Add 2002.12.15

 

    {公司徽标相关...}

    procedure ReadLogoItems(var TargetStream: TMemoryStream);    //Add 2002.12.15

    procedure WriteLogoItems(var TargetStream: TMemoryStream);   //Add 2002.12.15

 

    {其他信息}

    procedure ReadOtherInfo(var TargetStream: TMemoryStream);

    procedure WriteOtherInfo(var TargetStream: TMemoryStream);

 

    {汇总相关...}

    procedure ResetSumPage;                                      //复位汇总数据

    procedure ModifyPageSumLine(PageIndex: Integer);             //修改汇总的显示行

    Procedure DecPageSum(PageIndex: Integer);                    //汇总数据减少最后一个数据

    procedure AddSumLine(TitleText: string);                     //添加一个汇总行

    procedure CalculateSum(Value: Double; Index: Integer; KiloFmt: Boolean; Decimal: Integer); //计算汇总数据

    function AnalyzeSumCondition(Condition: string): Boolean;    //分析汇总条件

 

    procedure ReadSumItems(var TargetStream: TMemoryStream);     //向模板读写汇总信息

    procedure WriteSumItems(var TargetStream: TMemoryStream);

 

    procedure AddSumFiled(FieldIndex: Integer; Condition: string);  //添加汇总字段

    procedure ClearSumList;                                         //清空存放汇总类型的联表

 

    {行的操作}

    procedure AddLine;

    procedure UpdateLines(IsCalcVar: Boolean = False);

    procedure UpdatePrintLines(IsCalcVar: Boolean = False);

    procedure UpdateTempletLines;

    procedure SetAdjustLineHeight(Value: Integer); //Add 2002.12.15

 

    {选中区的操作}

    function IsAnyCellSelected: Boolean;

    function IsTheCellSelected(Cell: TReportCell): Boolean;

    function CellFromPoint(point: TPoint): TReportCell;

    function AddSelectedCell(Cell: TReportCell): Boolean;

    function RemoveSelectedCell(Cell: TReportCell): Boolean;

 

    {报表内容的计算相关...}

    procedure SetDataSet(const Value: TDataSet);

    procedure GetTextVarValue(var SourceStr: string);

    function GetVarValue(VarName: string): string;

 

    procedure AddTotalSumLine;

    procedure AboundLastPage(StandLine: TReportLine; HasSum: Boolean);

    procedure CombinePrintColumn(ColArray: TIntegerArray; RowCount: Integer);

    function IsInCombineColumn(ColArray: TIntegerArray; const Value: Integer): Boolean;

 

    {保存、加载报表计算结果}

    procedure SaveToResult(PageNumber: Integer);

    procedure LoadFromResult(PageNumber: Integer; IsView: Boolean = True);//IsView 是否看得见

 

    {打印输出相关...}

    procedure BorderFrame;

    procedure PrintOnePage;

 

    {设计对话框相关}

    procedure SetDesignDlgComponentStatus;

    procedure SetParamToDesignDlg;                    //设置DesignDlg窗体各项参数  //Modified 2002.12.15

    procedure SetNodesToDesignDlg;                    //根据FNodeList链表 设置DesignDlg窗体 '报表内容'TabSheet的参数

    procedure SetFieldItemsToDesignDlg;

    procedure GetParamFromDesignDlg;                  //得到DesignDlg窗体各项参数 //Modified 2002.12.15

    procedure GetNodesFromDesignDlg;                  //根据DesignDlg窗体 '报表内容'TabSheet 设置FNodeList链表的内容

    procedure SetColDataCellAtt(Font: TFont; Item: TNodeParam); overload;

    procedure SetColDataCellAtt(var ThisCell: TReportCell; Font: TFont; Item: TNodeParam);overload;

    procedure BuildTemplet;                           //创建模板

    procedure BuildTempletFrame(ColCount, RowCount: Integer); //生成模板的框架

    procedure BuildTempletHeader(DualLayer: Boolean); //创建模板的表头(合并Cell出外)

    procedure BuildTempletHeaderCombineCell;          //合并重建模板当中的合并Cell

    procedure BuildSumFiled;                          //创建汇总字段

    procedure ModifyTemplet;                          //修改模板

    procedure ModifyTempletHeaderCombineCell;         //合并修改模板当中的合并Cell

    procedure PrinterComboboxOnChange(Sender: TObject);

    procedure ReadNodeParam(var TargetStream: TMemoryStream);  //读取FNodeList链表内容

    procedure WriteNodeParam(var TargetStream: TMemoryStream); //写入FNodeList链表内容

 

    procedure SetFieldItems(List: TList);

 

    {画Bmp图片过程}

    procedure BltTBitmapAsDib(DestDc: HDC; X, Y, Width, Height: Word; Bmp: TBitmap);

    procedure DrawCellBitmap(hPaintDC: HDC; CellRect: TRect; Bit: TBitmap);

 

    procedure ItemPopMenuOnClick(Sender: TObject);

    procedure SysItemPopMenuOnClick(Sender: TObject);

    procedure SetPopupMenu(Value: TPopupMenu);

    procedure SetDesignPopupMenu(Value: TPopupMenu);

 

    {生成报表过程}

    function GetAProgressBar: TProgressBar;

 

    function StringsToIntArry(var ArrayList: TStringList; var IntArray: TIntegerArray): Boolean;

    function ModifySpecialTitle(var VarUnit: string): Boolean;  //用在PreparePrint_SpecialTitle过程中 修改表头部分

 

    procedure UpdateControlsPageButtonStatus;

 

    procedure PreparePrint_Normal;        // 0: 普通的生成报表过程

    procedure PreparePrint_MergeCol;      // 1: 有合并列的报表生成过程

    procedure PreparePrint_SpecialTitle;  // 2: 有特殊表头的报表生成过程

    procedure PreparePrint_FixedGrid;     // 5:固定网格的报表

  public

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

    procedure Notification(Component: TComponent; Operation: TOperation); override;

 

    {存取模板...}

    function SaveToFile(FileName: string): Boolean;

    function LoadFromFile(FileName: string): Boolean;

 

    function SaveToStream(Stream: TMemoryStream): Boolean;

    function LoadFormStream(Stream: TMemoryStream): Boolean;

 

    {View size}

    procedure AdjustSelfPositon;

    procedure SetScale(Value: Integer);

 

    {修改表格}

    function IsEmpty: Boolean;

    procedure CloseTable(IsFreeAll: Boolean = True);          //关闭当前表格

 

    procedure CombineCell;

    procedure CombinePrintCell;

    procedure VSplitCell(Number: Integer);

 

    {对当前选中单元格的属性操作}

    procedure GetCellAlign(var HorzAlign, VertAlign: Integer);

    procedure SetCellAlign(NewHorzAlign, NewVertAlign: Integer);

    procedure SetCellColor(NewTextColor, NewBackColor: COLORREF);

    procedure SetCellTextColor(NewTextColor: COLORREF);

    procedure SetCellBKColor(NewBackColor: COLORREF);

    procedure SetCellDiagonal(NewDiagonal: UINT);

    procedure SetCellFont(CellFont: TLOGFONT);

    procedure SetCellLines(bLeftLine, bTopLine, bRightLine, bBottomLine: Boolean;

      nLeftLineWidth, nTopLineWidth, nRightLineWidth, nBottomLineWidth: Integer);

    procedure SetCellLineColor(bLeftLine, bTopLine, bRightLine, bBottomLine: COLORREF);

    procedure SetCellText(Str: string);

    function GetCellText: string;

    procedure SetCellIsNum(var Value: Boolean);

    procedure SetCellIsKiloFmt(var Value: Boolean);

    procedure SetCellDecimal(var Value: Integer);

 

    {页面参数的设置...}

    procedure SetMargin(nLeftMargin, nTopMargin, nRightMargin, nBottomMargin: Integer);

    function GetMargin: TRect;

 

    function ExecuteDesignDlg: Boolean;

 

    {选中区的操作}

    procedure SelectCell(RowNum, ColNum: Integer; ClearExist: Boolean = False);

    procedure SelectLine(LineNum: Integer); {LineNum从1开始}

    procedure RemoveAllSelectedCell;

 

 

    {报表计算相关...}

    function IsSysVar(VarName: string): Boolean;  //是不是系统变量

    function AddVarItem(VarName, VarValue: string): Boolean; //如果是系统变量或者变量已经存在 则返回False  

    procedure ClearVarList;

 

    procedure PreparePrint;

 

    function UpdateTempletList: Boolean;

 

    {打印输出相关...}

    procedure PrintIt(DocTitle: string);

    procedure PrintAll(DocTitle: string; Order: Boolean);

    procedure PrintSelectPage(DocTitle: string; BPageNum, EPageNum: Integer);

    procedure ExcelExport;  //输出Excel

 

    {页码设置}

    procedure FirstPage;

    function PrevPage: Boolean;

    function NextPage: Boolean;

    procedure LastPage;

    function SelectPageNo(PageNo: Integer): Integer;

    function SelectPageNoByQDCode(QDCode: string): Integer;

 

    property FieldItems: TList read FFieldItemList write SetFieldItems;

    property CurPageNo: Integer read FCurPageNo;

    property PageCount: Integer read FPageCount;

    property ReportScale: Integer read FReportScale write SetScale default 100;

 

    property ReportSytle: Byte read FReportStyle write FReportStyle default 0;

    property IntArrayList: TStringList read FIntArrayList write FIntArrayList;

  published

    property Left;

    property Top;

    property Cursor;

    property Hint;

    property Visible default True;

    property Enabled default True;

 

    property AutoRefresh: Boolean read FAutoRefresh write FAutoRefresh;

    property ReadOnly: Boolean read FReadOnly write FReadOnly;

    property DataSet: TDataSet read FDataSet write SetDataSet;

    property AdjustLineHeight: Integer read FAdjustLineHeight write SetAdjustLineHeight;

    Property ReportLayout: TReportLayout read FLayout write FLayout;

    property ReportPrinter: TReportPrinter read FPrinter write FPrinter;

    property ReportControls: TControls read FControls write FControls;

    property StudyEdition: Boolean read FStudyEdition write FStudyEdition;

    property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;

    property DesignPopupMenu:TPopupMenu read FDesignPopupMenu write SetDesignPopupMenu;

 

    property OnSelected: TSelectEvent read FOnSelected write FOnSelected;

    property OnPreparing: TPreparingEvent read FOnPreparing write FOnPreparing;

  end;

 

  {---------------------------------------------------------------------------}

  PMyPaper = ^TMyPaper;

  TMyPaper = record

    PaperName: string;

    PaperMode: DWord;

  end;

 

  TReportPrinter = class(TPersistent)

  private

    FPrinters: TStrings;

    FPrinterPapers: TList;

    FPrinterBins: TStrings;

 

    FCurrentPaper: string;    //当前的纸张类型

    FSupportPaper: TStrings;  //所有支持的纸张类型

 

    FIsBusy: Boolean;

    FReportMaster: TReportMaster;

 

    function GetHandle: THandle; //句柄

    function GetCanvas: TCanvas; //画布

 

    function GetPrinters: TStrings;              //得到当前机器的所有打印机名称

    function GetPrinterIndex: Integer;           //得到当前打印机的序号

    function GetPrinterBins: TStrings;           //得到当前打印机的所有纸张来源

    function GetPrinterBinIndex: Integer;        //得到当前打印机的当前纸张来源

    function GetTitle: string;                   //得到打印标题

    function GetMyDitherType: TMyDitherType;     //得到抖动模式

    function GetMyDuplexType: TMyDuplexType;     //得到双工模式

    function GetMyOrientation: TMyOrientation;   //得到进纸模式

    function GetMyColorType: TMyColorType;       //得到色彩模式

    function GetMyPrintQuality: TMyPrintQuality; //得到打印品质

    function GetMagin(Index: Integer): Integer;  //得到打印边界

 

    //function GetPrinterPortNT(PrinterName: PChar): PChar;//得到基于WinNT架构操作系统的打印机的Port

    function GetIndexOf(APrinter: string): Integer;      //APrinter是第几个打印机?

 

    function GetPrinterInstalled: Boolean;//是否安装有打印机

    function GetPrinterSelected: Boolean; //是否有默认打印机

    function GetPrinterHeight: Integer;   //得到打印机当前的打印高度

    function GetPrinterWidth: Integer;    //得到打印机当前的打印宽度

    function GetPageHeight: Integer;      //得到打印机当前的纸张高度

    function GetPageWidth: Integer;       //得到打印机当前的纸张宽度

 

    procedure FreePrinters;               //Free打印机

    procedure UpdatePrinterPapers(NewPrinterIndex: Integer);  //更新当前打印机所支持的所有纸张类型

 

    procedure SetPrinterIndex(Index: Integer);                //设置当前打印机

    procedure SetPrinterBinIndex(Index: Integer);             //设置纸张来源

    procedure SetTitle(ATitle: string);                       //设置打印标题

    procedure SetMyDitherType(ADitherType: TMyDitherType);    //设置抖动模式

    procedure SetMyDuplexType(ADuplexType: TMyDuplexType);    //设置双工模式

    procedure SetMyOrientation(AOrientation: TMyOrientation); //设置进纸模式

    procedure SetMyPrintQuality(AQuality: TMyPrintQuality);   //设置打印品质

    procedure SetMyColorType(AColor: TMyColorType);           //设置色彩模式

    procedure SetMagin(Index, Value: Integer);                //设置页面边距

    procedure SetPaperSize(APapeName: string); //overload;    //设置纸张类型

    //procedure SetPaperSize(APapeMode: DWord);  overload;    //设置纸张类型

  public

    constructor Create(AOwner: TReportMaster);

    destructor Destroy; override;

 

    procedure BeginDoc;                    //开始打印

    procedure EndDoc;                      //结束打印

    procedure Abort;                       //中断打印

    procedure RefreshPrinters;             //刷新打印机设置

 

    procedure ResetPrinter;                //复位打印机

 

    function PrinterPpiX: Integer;         //X方向的PPi

    function PrinterPpiY: Integer;         //Y方向的PPi

 

    property Handle: THandle read GetHandle;

    property Canvas: TCanvas read GetCanvas;

    property PrinterWidth: Integer read GetPrinterWidth;

    property PrinterHeight: Integer read GetPrinterHeight;

 

    property PrinterNames: TStrings read GetPrinters;

    property PrinterSelected: Boolean read GetPrinterSelected;

 

    property IndexOf[Printer: string]: Integer read GetIndexOf;

    property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex;

    property PrinterBins: TStrings read GetPrinterBins;

    property PrinterBinIndex: Integer read GetPrinterBinIndex write SetPrinterBinIndex;

 

    property IsBusy: Boolean read FIsBusy default False;

 

    property Title: string read GetTitle write SetTitle;

 

    property PageHeight: Integer read GetPageHeight;

    property PageWidth: Integer read GetPageWidth;

  published

    property SupportPaper: TStrings read FSupportPaper;

    property CurrentPaper: string read FCurrentPaper write SetPaperSize;

    property ColorType: TMyColorType read GetMyColorType write SetMyColorType;

    property Orientation: TMyOrientation read GetMyOrientation write SetMyOrientation;

    property DitherType: TMyDitherType read GetMyDitherType write SetMyDitherType;

    property DuplexType: TMyDuplexType read GetMyDuplexType write SetMyDuplexType;

    property PrintQuality: TMyPrintQuality read GetMyPrintQuality write SetMyPrintQuality default knMedium;

 

    property PaperLeftMargin: Integer   Index 0 read GetMagin write SetMagin;

    property PaperRightMargin: Integer  Index 1 read GetMagin write SetMagin;

    property PaperTopMargin: Integer    Index 2 read GetMagin write SetMagin;

    property PaperBottomMargin: Integer Index 3 read GetMagin write SetMagin;

  end;

 

 

 

 {------------------------------------------------------------------------------}

 TReportLayout = class(TPersistent) {注意:这个报表页面设置类,只针对模板类型}

  private

    FSumExist: Boolean;  //是不是存在汇总字段

    FDblLayer: Boolean;  //是不是双层表头

    FTmpFont: TFont;     //临时交换用TFont

    FSelectCell: TReportCell;

    FReportMaster: TReportMaster;

 

    Procedure InitParam; //初始化必要的参数

 

    function GetIsLineShow(Index: Integer): Boolean;

    function GetHFStr(Index: Integer): string;

    function GetTitleStr(Index: Integer): string;

    function GetFieldText: string;

    function GetColor(Index: Integer): TColor;

    function GetFont(Index: Integer): TFont;

    function GetIsBordFrame: Boolean;

    function GetIsDisLine(Index: Integer): Boolean;

    function GetIsAutoFSize: Boolean;

    function GetDisPageCount: Boolean;

    function GetSumTitlePt: Integer;

    function GetSumDrawDiagonal: Boolean;

 

    procedure SetIsLineShow(Index: Integer; Value: Boolean);

    procedure SetHFStr(Index: Integer; Value: string);

    procedure SetTitleStr(Index: Integer; Value: string);

    procedure SetFieldText(Value: string);

    procedure SetColor(Index: Integer; Value: TColor);

    procedure SetFont(Index: Integer;  Value: TFont);

    procedure SetIsBordFrame(Value: Boolean);

    procedure SetIsDisLine(Index: Integer; Value: Boolean);

    procedure SetIsAutoFSize(Value: Boolean);

    procedure SetDisPageCount(Value: Boolean);

    procedure SetSumTitlePt(Value: Integer);

    procedure SetSumDrawDiagonal(Value: Boolean);

 

    function GetDataAlign: Integer;

    function GetDataColor: TColor;

    function GetDataDecimal: Integer;

    function GetDataFont: TFont;

    function GetDataKiloFmt: Boolean;

    function GetDataText: string;

 

    procedure SetDataColor(Value: TColor);

    procedure SetDataAlign(Value: Integer);

    procedure SetDataDecimal(Value: Integer);

    procedure SetDataFont(Value: TFont);

    procedure SetDataKiloFmt(Value: Boolean);

    procedure SetDataText(Value: string);

 

  public

    constructor Create(AOwner: TReportMaster);

    destructor Destroy; override;

    Procedure SelectDataCell(Index: Integer);

 

    Property DataText: string read GetDataText write SetDataText;

    Property DataColor: TColor read GetDataColor write SetDataColor;

    Property DataFont: TFont read GetDataFont write SetDataFont;

    Property DataAlign: Integer read GetDataAlign write SetDataAlign;

    Property DataDecimal: Integer read GetDataDecimal write SetDataDecimal;

    Property DataKiloFmt: Boolean read GetDataKiloFmt write SetDataKiloFmt;

 

    Property TitleString: string  Index 0 read GetTitleStr write SetTitleStr;//标题

    Property CaptnString: string  Index 1 read GetTitleStr write SetTitleStr;//表眉

    Property FieldText: string read GetFieldText write SetFieldText;

 

    Property TitleColor:   TColor  Index 0 read GetColor write SetColor;//页眉

    Property CaptionColor: TColor  Index 1 read GetColor write SetColor;//页脚

    Property FieldColor:   TColor  Index 2 read GetColor write SetColor;//表眉

    Property HorLineColor: TColor  Index 3 read GetColor write SetColor;//表头横线

    Property VerLineColor: TColor  Index 4 read GetColor write SetColor;//表头竖线

 

    Property TitleFont:   TFont  Index 0 read GetFont write SetFont;//页眉

    Property CaptionFont: TFont  Index 1 read GetFont write SetFont;//页脚

    Property FieldFont:   TFont  Index 2 read GetFont write SetFont;//表眉

 

  published

    Property HeaderString: string  Index 0 read GetHFStr write SetHFStr;//页眉

    Property FooterString: string  Index 1 read GetHFStr write SetHFStr;//页脚

 

    property SumTitlePt: Integer read GetSumTitlePt write SetSumTitlePt;

 

    property IsHeaderLine: Boolean Index 0 read GetIsLineShow write SetIsLineShow; //是否显示页眉线

    property IsFooterLine: Boolean Index 1 read GetIsLineShow write SetIsLineShow; //是否显示页脚线

    Property IsDisHorLine: Boolean index 0 read GetIsDisLine  write SetIsDisLine;  //换页是否加表头

    Property IsDisVerLine: Boolean index 1 read GetIsDisLine  write SetIsDisLine;  //换页是否加表头

    Property IsBordFrame   : Boolean read GetIsBordFrame   write SetIsBordFrame;   //是否加粗边框

    property IsAutoFSize   : Boolean read GetIsAutoFSize   write SetIsAutoFSize;   //纸张类型改变大后是否相应变大字体 (默认为不改变 False)

    property IsDisPageCount: Boolean read GetDisPageCount  write SetDisPageCount;

    property IsSumDrawDiagonal: Boolean read GetSumDrawDiagonal write SetSumDrawDiagonal; //汇总行在无内容部分是不是画斜线

  end;

 

  {----------------------------------------------------------------------------}

  TTPrinterDevice = class(TObject) {打印设备类、用来存储当前打印机。TReportPrinter类用到,}

  public

    Driver, Device, Port: string; //驱动、设备、端口

    constructor Create(ADriver, ADevice, APort: PChar);

  end;

 

  {----------------------------------------------------------------------------}

  TTSumItem = class(TObject) {汇总使用}

  public

    LastNum: Double;          // 最后添加的数据

    FieldIndex: Integer;      // 汇总第几个字段  (第一个从0开始)

    Condition: string;        // 条件

    PageSum: array of Double; // 当前页的汇总值 如:第一页是PageSum[0], 第二页PageSum[1]

    AllSum: Double;           // 到第几页之前的所有页汇总的和

 

    IsKiloFmt: Boolean;       // 是否千分位显示

    Decimal: Integer;         // 显示几位小数

  end;

 

  {----------------------------------------------------------------------------}

  TTVarItem = class(TObject) {设置变量使用}

  public

    VarName: string;

    VarValue: string;

  end;

 

  {----------------------------------------------------------------------------}

  TTCellTable = class(TObject) {在解决 Cell的隶属关系时用到}

  public

    PrevCell: TReportCell;

    ThisCell: TReportCell;

  end;

 

  {----------------------------------------------------------------------------}

  TTMyRect = class(TObject)  {在合并Cell的时候用到}

  public

    Left: Integer;

    Top: Integer;

    Right: Integer;

    Bottom: Integer;

  end;

 

  {---------------------------------------------------------------------------}

  {为 ReportDesign 窗体中的 ColData ComboBox添加Items 用到的类}

 

  TTFieldItem = class(TObject)

  public

    ItemStr: string;

    IsNum: Boolean;

  end;

 

 

  {---------------------------------------------------------------------------}

  {公司徽标}

 

  TTLogoBmp = class(TObject)    // Add 2002.12.15

  Public

    Bmp: TBitmap;

    IsTop: Boolean;

    IsLeft: Boolean;

  end;

 

  {为 临时文件的序列 随机产生文件名}   //Delete 2002.12.15

  {

  TTFileItem = class(TObject)

  public

    Index: Integer;

    FileName: string;

  end;

  }

1.2 ReportFairy

1.2.1 说明

制造表格的组件,其大部分原理和第一个组件一样,只是本组件只是用来实现制作表格的,比第一个的使用方法还简单,无需多说,看Demo吧!(在   .\Samples\表格”  目录)

1.2.2 单元声明

unit ReportFairy;

 

interface

                   

uses

  Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms, Dialogs, Registry,

  Printers, WinSpool, Variants, ComObj, ExtCtrls, StdCtrls, ComCtrls, Menus, Buttons,

  Spin, ReportFunc;

 

const

  { Horz Align }

  ALIGN_LEFT = 0;

  ALIGN_HCENTER = 1;

  ALIGN_RIGHT = 2;

 

  { Vert Align }

  ALIGN_TOP = 0;           

  ALIGN_VCENTER = 1;

  ALIGN_BOTTOM = 2;

 

  {Mix Cell Height}

  CELLMINHEIGHT = 16;

 

  {标记}

  MK_LR_LINE = 1;        { 左斜线 }

  MK_RL_LINE = 2;        { 右斜线 }

  MK_CIRCLE = 4;         { 圆圈   }

  MK_ELLIPSE = 8;        { 椭圆   }

  MK_FIT = $10;          { 对勾   }

  MK_LEFT_LINE = $20;    { 左边线 }

  MK_TOP_LINE = $40;     { 上边线 }

  MK_RIGHT_LINE = $80;   { 右边线 }

  MK_BOTTOM_LINE = $100; { 下边线 }

  MK_ERROR = $200;       { 叉   }

 

  {常用的打印纸张类型 53种}

  DMPAPER_LETTER         = 1;   { Letter 8 12 x 11 in             }

  DMPAPER_LETTERSMALL    = 2;   { Letter Small 8 12 x 11 in       }

  DMPAPER_TABLOID        = 3;   { Tabloid 11 x 17 in              }

  DMPAPER_LEDGER         = 4;   { Ledger 17 x 11 in               }

  DMPAPER_LEGAL          = 5;   { Legal 8 12 x 14 in              }

  DMPAPER_STATEMENT      = 6;   { Statement 5 12 x 8 12 in        }

  DMPAPER_EXECUTIVE      = 7;   { Executive 7 14 x 10 12 in       }

  DMPAPER_A3             = 8;   { A3 297 x 420 mm                 }

  DMPAPER_A4             = 9;   { A4 210 x 297 mm                 }

  DMPAPER_A4SMALL        = 10;  { A4 Small 210 x 297 mm           }

  DMPAPER_A5             = 11;  { A5 148 x 210 mm                 }

  DMPAPER_B4             = 12;  { B4 (JIS) 250 x 354              }

  DMPAPER_B5             = 13;  { B5 (JIS) 182 x 257 mm           }

  DMPAPER_FOLIO          = 14;  { Folio 8 12 x 13 in              }

  DMPAPER_QUARTO         = 15;  { Quarto 215 x 275 mm             }

  DMPAPER_10X14          = 16;  { 10x14 in                        }

  DMPAPER_11X17          = 17;  { 11x17 in                        }

  DMPAPER_NOTE           = 18;  { Note 8 12 x 11 in               }

  DMPAPER_ENV_9          = 19;  { Envelope #9 3 78 x 8 78         }

  DMPAPER_ENV_10         = 20;  { Envelope #10 4 18 x 9 12        }

  DMPAPER_ENV_11         = 21;  { Envelope #11 4 12 x 10 38       }

  DMPAPER_ENV_12         = 22;  { Envelope #12 4 \276 x 11        }

  DMPAPER_ENV_14         = 23;  { Envelope #14 5 x 11 12          }

  DMPAPER_ENV_DL         = 27;  { Envelope DL 110 x 220mm         }

  DMPAPER_ENV_C5         = 28;  { Envelope C5 162 x 229 mm        }

  DMPAPER_ENV_C3         = 29;  { Envelope C3  324 x 458 mm       }

  DMPAPER_ENV_C4         = 30;  { Envelope C4  229 x 324 mm       }

  DMPAPER_ENV_C6         = 31;  { Envelope C6  114 x 162 mm       }

  DMPAPER_ENV_C65        = 32;  { Envelope C65 114 x 229 mm       }

  DMPAPER_ENV_B4         = 33;  { Envelope B4  250 x 353 mm       }

  DMPAPER_ENV_B5         = 34;  { Envelope B5  176 x 250 mm       }

  DMPAPER_ENV_B6         = 35;  { Envelope B6  176 x 125 mm       }

 

  DMPAPER_9X11           = 44;  { 9 x 11 in                       }

  DMPAPER_10X11          = 45;  { 10 x 11 in                      }

  DMPAPER_15X11          = 46;  { 15 x 11 in                      }

  DMPAPER_LETTER_EXTRA   = 50;  { Letter Extra 9 \275 x 12 in     }

  DMPAPER_LEGAL_EXTRA    = 51;  { Legal Extra 9 \275 x 15 in      }

  DMPAPER_TABLOID_EXTRA  = 52;  { Tabloid Extra 11.69 x 18 in     }

  DMPAPER_A4_EXTRA       = 53;  { A4 Extra 9.27 x 12.69 in        }

  DMPAPER_A4_TRANSVERSE  = 55;  { A4 Transverse 210 x 297 mm      }

  DMPAPER_A5_TRANSVERSE  = 61;  { A5 Transverse 148 x 210 mm      }

  DMPAPER_B5_TRANSVERSE  = 62;  { B5 (JIS) Transverse 182 x 257 mm}

  DMPAPER_A3_TRANSVERSE  = 67;  { A3 Transverse 297 x 420 mm      }

  DMPAPER_PENV_1         = 96;  { PRC Envelope #1 102 x 165 mm    }

  DMPAPER_PENV_2         = 97;  { PRC Envelope #2 102 x 176 mm    }

  DMPAPER_PENV_3         = 98;  { PRC Envelope #3 125 x 176 mm    }

  DMPAPER_PENV_4         = 99;  { PRC Envelope #4 110 x 208 mm    }

  DMPAPER_PENV_5         = 100; { PRC Envelope #5 110 x 220 mm    }

  DMPAPER_PENV_6         = 101; { PRC Envelope #6 120 x 230 mm    }

  DMPAPER_PENV_7         = 102; { PRC Envelope #7 160 x 230 mm    }

  DMPAPER_PENV_8         = 103; { PRC Envelope #8 120 x 309 mm    }

  DMPAPER_PENV_9         = 104; { PRC Envelope #9 229 x 324 mm    }

  DMPAPER_PENV_10        = 105; { PRC Envelope #10 324 x 458 mm   }

 

  { 打印机抖动模式}

  DMDITHER_NONE      = 1;     { 不抖动  }

  DMDITHER_COARSE    = 2;     { 粗糙画笔模式  }

  DMDITHER_FINE      = 3;     { 优秀画笔模式  }

  DMDITHER_LINEART   = 4;     { 艺术抖动模式  }

  DMDITHER_GRAYSCALE = 10;    { 灰度抖动模式  }

 

  { 打印机双工模式 }

  DMDUP_SIMPLEX    = 1;       { 简单双工模式 }

  DMDUP_VERTICAL   = 2;       { 纵向双工模式 }

  DMDUP_HORIZONTAL = 3;       { 横向双工模式 }

 

  { 打印机的色彩模式 }

  DMCOLOR_MONOCHROME = 1;     { 单色模式 }

  DMCOLOR_COLOR = 2;          { 彩色模式 }

 

  { 打印机打印品质 }

  DMRES_DRAFT = LongWord(-1);   { 草图 }

  DMRES_LOW = LongWord(-2);     { 一般 }

  DMRES_MEDIUM = LongWord(-3);  { 中等 }

  DMRES_HIGH = LongWord(-4);    { 优秀 }

 

  {默认打印机分辨率}

  DEFAULT_PRINTER_PPI = 360;

 

const

  RichEditModuleName = 'RICHED32.DLL';

 

type

  TReportCell = class;

  TReportLine = class;

  TReportFairy = class;

  TReportPrinter = class;

 

  PPArray = ^TPArray;

  TPArray = array[0..4] of TPoint;  

  TIntegerArray = array of Integer;

  TMemoryArray = array of TMemoryStream;

 

 

  PPalEntriesArray = ^TPalEntriesArray; {for palette re-construction}

  TPalEntriesArray = array[0..0] of TPaletteEntry;

 

  {打印机参数}

  TMyOrientation = (knPortrait, knLandscape);

  TMyColorType = (knColor, knMonochrome);

  TMyDuplexType = (knSimplex, knHorzDuplex, knVertDuplex);

  TMyDitherType = (knNone, knCourse, knFine, knLineArt, knGrayScale);

  TMyPrintQuality = (knDraft, knLow, knMedium, knHigh);

 

  TMyViewState= (knHundred, knWidth, knHeight);

 

  TSelectEvent = procedure(Cell: TReportCell; Button: TMouseButton; X, Y: Integer) of object;

  TClickEvent = procedure(Sender: TObject) of object;

  {----------------------------------------------------------------------------}

 

  TControls = class(TPersistent)

  private

    FReportFairy: TReportFairy;

 

    FProgress: TStatusBar;

    FProgressRect: TRect;

    FProgressPanel: TStatusPanel;

 

    FLeftLineWidth  : TSpinEdit;

    FRightLineWidth : TSpinEdit;

    FTopLineWidth   : TSpinEdit;

    FBottomLineWidth: TSpinEdit;

 

    FLeftLineShow  : TCheckBox;

    FRightLineShow : TCheckBox;

    FTopLineShow   : TCheckBox;

    FBottomLineShow: TCheckBox;

 

    FLeftLineColor    : TColorBox;

    FRightLineColor   : TColorBox;

    FTopLineColor     : TColorBox;

    FBottomLineColor  : TColorBox;

    FCellTextColor    : TColorBox;

    FCellBKGroudColor : TColorBox;

 

    FReadOnly: TSpeedButton;

    FCellPicture: TSpeedButton;

    FCellVertText: TSpeedButton;

    FCellVarList : TComboBox;

    FZoomScale: TComboBox;

 

    procedure ZoomScaleChange(Sender: TObject);

    procedure ProcessDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);

  protected

    procedure SetLabel(Index: Integer; Value: TCustomLabel);

    procedure SetStatusBar(Value: TStatusBar);

    procedure SetComboBox(Value: TComboBox);

    procedure SetShowLine(Index: Integer; Value: TCheckBox);

    procedure SetLineWidth(Index: Integer; Value: TSpinEdit);

    procedure SetLineColor(Index: Integer; Value: TColorBox);

    procedure SetCellVarList(Value: TComboBox);

 

    procedure SetCellStatus(Index: Integer; Value: TSpeedButton);

 

    procedure LeftLineShowClick(Sender: TObject);

    procedure RightLineShowClick(Sender: TObject);

    procedure TopLineShowClick(Sender: TObject);

    procedure BottomLineShowClick(Sender: TObject);

    //procedure AllLineShowClick(Sender: TObject);

 

    procedure LeftLineColorChange(Sender: TObject);

    procedure RightLineColorChange(Sender: TObject);

    procedure TopLineColorChange(Sender: TObject);

    procedure BottomLineColorChange(Sender: TObject);

    procedure TextColorChange(Sender: TObject);

    procedure BKGroundColorChange(Sender: TObject);

 

    procedure LeftLineWidthChange(Sender: TObject);

    procedure RightLineWidthChange(Sender: TObject);

    procedure TopLineWidthChange(Sender: TObject);

    procedure BottomLineWidthChange(Sender: TObject);

 

    procedure CellReadOnlyClick(Sender: TObject);

    procedure CellVarListChange(Sender: TObject);

    procedure CellVertTextClick(Sender: TObject);

  public

    constructor Create(AOwner: TReportFairy);

  published

    property Progress: TStatusBar read FProgress write SetStatusBar;

    Property ZoomScale: TComboBox  read FZoomScale write SetComboBox;

    property CellVarList: TComboBox read FCellVarList write SetCellVarList;

 

    property CellReadOnly    : TSpeedButton index 0 read FReadOnly     write SetCellStatus;

    property CellPicture     : TSpeedButton index 1 read FCellPicture  write SetCellStatus;

    property CellVertText    : TSpeedButton index 2 read FCellVertText write SetCellStatus;

 

    property lsLeftLine  : TCheckBox index 0 read FLeftLineShow   write SetShowLine;

    property lsRightLine : TCheckBox index 1 read FRightLineShow  write SetShowLine;

    property lsTopLine   : TCheckBox index 2 read FTopLineShow    write SetShowLine;

    property lsBottomLine: TCheckBox index 3 read FBottomLineShow write SetShowLine;

    //property lsAllLine   : TCheckBox index 4 read FAllLineShow    write SetShowLine;

 

    property lwLeftLine  : TSpinEdit index 0 read FLeftLineWidth   write SetLineWidth;

    property lwRightLine : TSpinEdit index 1 read FRightLineWidth  write SetLineWidth;

    property lwTopLine   : TSpinEdit index 2 read FTopLineWidth    write SetLineWidth;

    property lwBottomLine: TSpinEdit index 3 read FBottomLineWidth write SetLineWidth;

 

    property lcLeftLine  : TColorBox index 0 read FLeftLineColor   write SetLineColor;

    property lcRightLine : TColorBox index 1 read FRightLineColor  write SetLineColor;

    property lcTopLine   : TColorBox index 2 read FTopLineColor    write SetLineColor;

    property lcBottomLine: TColorBox index 3 read FBottomLineColor write SetLineColor;

    property lcTextColor : TColorBox index 4 read FCellTextColor   write SetLineColor;

    property lcBKGroudColor : TColorBox index 5 read FCellBKGroudColor   write SetLineColor;

  end;

                  

 

  {-------------------------------------------------------------------------------}

  TReportCell = class(TObject)

  private

    FLeftMargin: Integer;    // 左边的空格

    FOwnerLine: TReportLine; // 隶属行

 

    {隶属和覆盖的单元格仅限于纵向,因为只有纵向的覆盖在高度上才会引起不同}

    FOwnerCell: TReportCell; // 隶属的单元格

    FCellsList: TList;       // 覆盖的Cell,在FCellsList中存放TReportCell

 

    {Index}

    FCellIndex: Integer; // Cell在行中的索引

 

    {size & position}

    FCellLeft: Integer;

    FCellWidth: Integer;

 

    FCellRect: TRect; // 计算得来

    FTextRect: TRect;

 

    FDragCellHeight: Integer;

    FMinCellHeight: Integer;

    FRequiredCellHeight: Integer;

 

    {Border}

    FLeftLine: Boolean;

    FLeftLineWidth: Integer;

 

    FTopLine: Boolean;

    FTopLineWidth: Integer;

 

    FRightLine: Boolean;

    FRightLineWidth: Integer;

 

    FBottomLine: Boolean;

    FBottomLineWidth: Integer;

 

    FIsVar: Boolean;         {是否是变量}

    FReadOnly: Boolean; {if Cell's OwnerLine = nil then FReadOnly means Visilbe}

 

    {标记}

    FMarker: UINT;  //左斜线、右斜线、圆圈、对勾

 

    {是否竖向显示文字}

    FVertText: Boolean; //

 

    {Color}

    FTextColor: COLORREF;

    FBackGroundColor: COLORREF;

 

    FTopLineColor: COLORREF;

    FBottomLineColor: COLORREF;

    FLeftLineColor: COLORREF;

    FRightLineColor: COLORREF;

 

    {Align}

    FHorzAlign: Integer;

    FVertAlign: Integer;

 

    {string}

    FCellText: string;

 

    {FVarText}

    FVarText: string;

 

    {Font}

    FLogFont: TLOGFONT;

 

    {Bitmap}

    FIsPic: Boolean;

    FBitmap: TBitmap;

    FDataStream: TMemoryStream;

 

  protected

    procedure SetLeftMargin(Value: Integer);

    procedure SetCellLeft(Value: Integer);

    procedure SetCellWidth(Value: Integer);

    procedure SetCellText(Value: string);

    procedure SetLogFont(Value: TLOGFONT);

    procedure SetOwnerLine(Value: TReportLine);

    procedure SetOwnerCell(Value: TReportCell);

    procedure SetLineWidth(Index, Value: Integer);

    procedure SetLineShow(Index: Integer; Value: Boolean);

    procedure SetLineColor(Index: Integer; Value: COLORREF);

    procedure SetBitmapStream(Value: TMemoryStream);

 

    function GetLineWidth(Index: Integer): Integer;

    function GetLineShow(Index: Integer): Boolean;

    function GetLineColor(Index: Integer): COLORREF;

    function GetCellHeight: Integer;

    function GetCellTop: Integer;

    function GetOwnerLineHeight: Integer;

    function GetOwnedCellCount: Integer;

    function GetBitmapStream: TMemoryStream;

 

    function GetIsHasPic: Boolean;

    procedure SetVarText(const Value: string);

  public

    constructor Create;

    destructor Destroy; override;

 

    procedure AddOwnedCell(Cell: TReportCell);

    procedure RemoveAllOwnedCell;

    procedure RemoveOwnedCell(Cell: TReportCell);

    function IsCellOwned(Cell: TReportCell): Boolean;

 

    procedure CalcCellRect;

    procedure CalcMinCellHeight;

    procedure PaintCell(hPaintDC: HDC; bFormatPrint: Boolean = False); //overload;

    procedure PaintCellEx(hPaintDC: HDC; WillVisble: Boolean);

    procedure CopyCell(Cell: TReportCell; bInsert: Boolean);

    //procedure PaintCell(hPaintDC: HDC; bPrint: Boolean); overload;

    //procedure PaintSelectedCell(hPaintDC: HDC);

 

    {Properties}

    property LeftMargin: Integer read FLeftMargin write SetLeftMargin;

    property OwnerLine: TReportLine read FOwnerLine write SetOwnerLine;

    property OwnerCell: TReportCell read FOwnerCell write SetOwnerCell;

    property OwnedCellCount: Integer read GetOwnedCellCount;

 

    property CellIndex: Integer read FCellIndex write FCellIndex;

 

    {size & position}

    property CellLeft: Integer read FCellLeft write SetCellLeft;

    property CellWidth: Integer read FCellWidth write SetCellWidth;

    property CellTop: Integer read GetCellTop;

    property CellHeight: Integer read GetCellHeight;

 

    property CellRect: TRect read FCellRect;

    property TextRect: TRect read FTextRect;

 

    property DragCellHeight: Integer read FDragCellHeight;

    property MinCellHeight: Integer read FMinCellHeight;

    property RequiredCellHeight: Integer read FRequiredCellHeight;

    property OwnerLineHeight: Integer read GetOwnerLineHeight;

 

    {Border}

    property LeftLine:   Boolean index 0 read GetLineShow write SetLineShow default True;

    property TopLine:    Boolean index 1 read GetLineShow write SetLineShow default True;

    property RightLine:  Boolean index 2 read GetLineShow write SetLineShow default True;

    property BottomLine: Boolean index 3 read GetLineShow write SetLineShow default True;

 

    {LineWidth}

    property LeftLineWidth  : Integer index 0 read GetLineWidth write SetLineWidth default 1;

    property TopLineWidth   : Integer index 1 read GetLineWidth write SetLineWidth default 1;

    property RightLineWidth : Integer index 2 read GetLineWidth write SetLineWidth default 1;

    property BottomLineWidth: Integer index 3 read GetLineWidth write SetLineWidth default 1;

 

    {Color}

    property TopLineColor   : COLORREF index 0 read GetLineColor write SetLineColor default clBlack;

    property BottomLineColor: COLORREF index 1 read GetLineColor write SetLineColor default clBlack;

    property LeftLineColor  : COLORREF index 2 read GetLineColor write SetLineColor default clBlack;

    property RightLineColor : COLORREF index 3 read GetLineColor write SetLineColor default clBlack;

    property TextColor      : COLORREF index 4 read GetLineColor write SetLineColor default clBlack;

    property BackGdColor    : COLORREF index 5 read GetLineColor write SetLineColor default clWhite;

 

    {斜线}

    property Marker: UINT read FMarker write FMarker;

 

    {Align}

    property HorzAlign: Integer read FHorzAlign write FHorzAlign default 1;

    property VertAlign: Integer read FVertAlign write FVertAlign default 1;

 

    {string}

    property CellText: string read FCellText write SetCellText;

    property VarText: string read FVarText write SetVarText;

 

    {Font}

    property LogFont: TLOGFONT read FLogFont write SetLogFont;

 

    property IsHasPic: Boolean read GetIsHasPic;

    property IsPic: Boolean read FIsPic write FIsPic;

    property DataStream: TMemoryStream read FDataStream write FDataStream;

    property BitmapStream: TMemoryStream read GetBitmapStream  write SetBitmapStream;

 

    property IsVarCell: Boolean read FIsVar;

    property IsReadOnly: Boolean read FReadOnly;

    property IsVertText: Boolean read FVertText;

 

    {格式化套打}

    //property IsFormatPrint: Boolean read FFormatPrint write FFormatPrint;

  end;

 

  {----------------------------------------------------------------------------}

  TReportLine = class(TObject)

  private

    FReportFairy: TReportFairy;

    FCells: TList;                // 保存所有在该行中的CELL

    FLineIndex: Integer;          // 行的索引

 

    FMinHeight: Integer;

    FDragHeight: Integer;

    FLineTop: Integer;

    FLineRect: TRect;

  protected

    function GetLineHeight: Integer;

    function GetLineRect: TRect;

 

    procedure SetDragHeight(Value: Integer);

    procedure SetLineTop(Value: Integer);

  public

    procedure CalcLineHeight;

    procedure CreateLine(LineLeft, CellNumber, PageWidth: Integer);overload;

    procedure CreateLine(LineLeft, PageWidth: Integer; ColScale: TIntegerArray);overload;

    procedure CopyLine(Line: TReportLine; bInsert: Boolean);

 

    constructor Create(AOwner: TReportFairy);

    destructor Destroy; override;

 

    property LineIndex: Integer read FLineIndex write FLineIndex;

    property LineHeight: Integer read GetLineHeight write SetDragHeight;

    property LineTop: Integer read FLineTop write SetLineTop;

    property LineRect: TRect read GetLineRect;

    property PrevLineRect: TRect read FLineRect;

  end;

 

  {----------------------------------------------------------------------------}

  TReportFairy = class(TWinControl)

  private

    FAppDir: string;    //Application的Dir

 

    FCellListEx: TList;    // 存放Cell的List

    FSelectCells: TList; //存放选中Cell的链表

    FSelectCellsEx: TList;

    FLineList: TList;    //保存当前显示页的信息

    FVarList: TList;     //保存变量的名字和值的对照表

 

    FEditCell: TReportCell;

    FPreHintCell: TReportCell;

    FCurHintCell: TReportCell;

 

    FAdjustLineHeight: Integer; //行高的调整系数(单位:象素)  Add 2002.12.15

 

    FHeaderList: TList;

    FFooterList: TList;

 

    FPopupMenu: TPopupMenu;

    FTempFont: TFont;

 

    FHeaderLine: Boolean; //是否现实页眉分隔线

    FFooterLine: Boolean; //是否现实页脚分隔线

 

    FOldPageWidth, FOldPageHeight: Integer; //保存上一次页面大小设置后的纸张大小

    FAdaptFontSize: Boolean;                //纸张类型改变变大后是否相应变大字体 (默认为改变 True)

    FEditing: Boolean;                      //报表是否允许编辑

    FLockGrid: Boolean;                     //是否锁定表格网格

    FStudyEdition: Boolean;                 //是否学习版本?

    FAutoTableSize: Boolean;                //表格自动随页面设置大小变化

    FSwithView: Boolean;

 

    {显示、打印参数相关...}

    FPrinter: TReportPrinter;     //打印机Class

    FPaperName: string;           //当前纸张类型名称 从打印机Class获得

    FOrientation: TMyOrientation; //纸张进纸方向 也从打印机Calss获得

    FReportScale: Integer;        //显示比例

    FViewState: TMyViewState;

    FPageWidth: Integer;          //纸张宽度

    FPageHeight: Integer;         //纸张高度

 

    FControls: TControls;

 

    FLeftMargin: Integer;   //边距  (单位:象素)

    FRightMargin: Integer;

    FTopMargin: Integer;

    FBottomMargin: Integer;

 

    FLeftMargin1: Integer;  //边距  (单位:mm)

    FRightMargin1: Integer;

    FTopMargin1: Integer;

    FBottomMargin1: Integer;

 

    {鼠标操作支持}

    FMousePoint: TPoint;

    FDragState: Boolean;

 

    {编辑、颜色及字体}

    FEditWnd: HWND;

    FEditBrush: HBRUSH;

    FEditFont: HFONT;

 

    FOnClick: TClickEvent;

    FOnSelected: TSelectEvent;

  protected

    procedure CreateWnd; override;

    procedure BateEdition(hPaintDC: HDC);

 

    {Windows消息相关...}

    procedure WMPaint(var Message: TMessage); message WM_PAINT;

    procedure WMLButtonUp(var Message: TMessage); message WM_LBUTTONUP;

    procedure WMLButtonDown(var Message: TMessage); message WM_LBUTTONDOWN;

    procedure WMRButtonDown(var Message: TMessage); message WM_RBUTTONDOWN;

    procedure WMLButtonDBLClk(var Message: TMessage); message WM_LBUTTONDBLCLK;

    procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE;

    procedure WMContextMenu(var Message: TMessage); message WM_CONTEXTMENU;

    procedure WMCommand(var Message: TMessage); message WM_COMMAND;

    procedure WMCTLColor(var Message: TMessage); message WM_CTLCOLOREDIT;

    procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;

    procedure WMKeyUP(var Message: TWMKeyUP); message WM_KEYUP;

 

    {WMLButtonDown消息触发的过程...}

    procedure SwithViewScale;

    procedure DecorateHintCell;

    procedure KillHintCell;

    procedure DecorateEditCell(Cell: TreportCell);

    procedure KillEditCell(GetText: Boolean = True);

    procedure StartMouseDrag(point: TPoint);

    procedure StartMouseSelect(point: TPoint);//; bSelectFlag: Boolean);

    procedure MouseMoveSeriesSelect(message: TMSG);

 

    function IsPointInPage(Point: TPoint): Boolean;

    procedure InitPArrayList(var ArrayList: TList);

    procedure GetMoveCellsBorder(var BorderRect: TRect; bPoint: TPoint);

    procedure StartCellDrag(var Cell: TReportCell; bPoint: TPoint; bHorz: Boolean);

    procedure StartCellsMove(var Cell: TReportCell; bPoint: TPoint);

 

    {Window size}

    procedure CalcWndSize(Flag: Boolean);

 

    {链表操作相关...}

    procedure CopyReportLineList(var DestList, SourceList: TList; IsFull: Boolean);

 

    {页眉页脚、表头相关...}

    procedure CreateHeaderList;

    procedure CreateFooterList;

 

    procedure SetHFStrings(Index: Integer; Value: string); // Index 为0为页眉  1为页脚

    Procedure SetHFLineShow(Index: Integer; Value: Boolean);

    function GetHFStrings(Index: Integer): string;

    function GetHFLineShow(Index: Integer): Boolean;

 

    procedure AnalyzeHFStrings(var Title: string; var StrList: TStringList);

    procedure UpdateHeaderFooterSize;              //更新页眉页脚尺寸

    procedure UpdateHeaderFooterText(BL: Boolean); //更新页眉页脚内容

 

    procedure ReadHeaderFooter(IsHeader: Boolean; var MStream: TMemoryStream);

    procedure WriteHeaderFooter(IsHeader: Boolean; var MStream: TMemoryStream);

    procedure ReadBitmapCell(var MStream: TMemoryStream);

    procedure WriteBitmapCell(var MStream: TMemoryStream);

    procedure ReadFlagCell(var MStream: TMemoryStream);

    procedure WriteFlagCell(var MStream: TMemoryStream);

 

    {行的操作}

    procedure UpdateLines;

    procedure SetAdjustLineHeight(Value: Integer); //Add 2002.12.15

 

 

    {选中区的操作}

    function CellFromPoint(point: TPoint): TReportCell;

 

    function IsTheCellSelected(Cell: TReportCell): Boolean;

    function AddSelectedCell(Cell: TReportCell): Boolean;

    function RemoveSelectedCell(Cell: TReportCell): Boolean;

 

    function IsTheCellSelectedEx(Cell: TReportCell): Boolean;

    function AddSelectedCellEx(Cell: TReportCell): Boolean;

    function RemoveSelectedCellEx(Cell: TReportCell): Boolean;

    procedure RemoveAllSelectedCellEx;

 

    function GetCurrentCell: TReportCell;

    function GetFlagCell: TReportCell;

 

    procedure GetAroundCell(ThisCell: TReportCell; var LeftCell, TopCell, RightCell, BottomCell: TReportCell);

 

    procedure UpdateFControls(Cell: TReportCell);

 

    {报表内容的计算相关...}

    procedure GetTextVarValue(var SourceStr: string);

    function GetVarValue(VarName: string): string;

 

    {画Bmp图片过程}

    procedure BltTBitmapAsDib(DestDc: HDC; X, Y, Width, Height: Word; Bmp: TBitmap);

    procedure DrawCellBitmap(hPaintDC: HDC; CellRect: TRect; Bit: TBitmap);

 

    procedure SetPopupMenu(Value: TPopupMenu);

    procedure SetLockGrid(Value: Boolean);

    procedure SetEditing(Value: Boolean);

  public

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

    procedure Notification(Component: TComponent; Operation: TOperation); override;

 

    {存取模板...}

    function SaveTempletFile(FileName: string): Boolean;

    function LoadTempletFile(FileName: string): Boolean;

 

    function SaveToStream(Stream: TMemoryStream): Boolean;

    function LoadFromStream(Stream: TMemoryStream): Boolean;

 

 

    function SaveTempletFileEx(FileName: string): Boolean;

    function LoadTempletFileEx(FileName: string): Boolean;

 

    function SaveToStreamEx(Stream: TMemoryStream): Boolean;

    function LoadFromStreamEx(Stream: TMemoryStream): Boolean;

 

    {View size}

    procedure UpdateLineSize;      //随打印机纸张变化 自动调整大小

    procedure RegulatePageSize;    //由于不同打印机有细微的差别 所以对相同设置 但是不同大小的表格进行调整

    procedure RegulateLineHeight;

    procedure SetScale(Value: Integer);

 

    {修改表格}

    function IsEmpty: Boolean;

    procedure NewTable(ColNumber, RowNumber: Integer);overload;

    procedure NewTable(RowNumber: Integer; ColumnArray: TIntegerArray); overload;

    procedure CloseTable; //关闭当前表格

 

    procedure AddCell;

    procedure DeleteCell;

    procedure InsertCell;

 

    procedure CombineCell;

    procedure VSplitCell(Number: Integer);

    procedure HSplitCell;

 

    procedure AddLine;

    procedure InsertLine;

    procedure DeleteLine;

 

    {单元格的属性}

    procedure SetCellLines(bLeftLine, bTopLine, bRightLine, bBottomLine: Boolean;

      nLeftLine, nTopLine, nRightLine, nBottomLine: Integer);

    procedure GetCellLines(var bLeftLine, bTopLine, bRightLine, bBottomLine: Boolean;

      var nLeftLine, nTopLine, nRightLine, nBottomLine: Integer);

 

    procedure SetCellLineVisible(LeftLine, TopLine, RightLine, BottomLine: Boolean);

    procedure GetCellLineVisible(var LeftLine, TopLine, RightLine, BottomLine: Boolean);

 

    procedure SetCellLineWidth(LeftLine, TopLine, RightLine, BottomLine: Integer);

    procedure GetCellLineWidth(var LeftLine, TopLine, RightLine, BottomLine: Integer);

 

    procedure SetCellLineColor(LeftLine, TopLine, RightLine, BottomLine: COLORREF);

    procedure GetCellLineColor(var LeftLine, TopLine, RightLine, BottomLine: COLORREF);

 

    procedure SetCellVariable(IsVar: Boolean; VarName: string = '');

    procedure GetCellVariable(var IsVar: Boolean; var VarName: string);

 

    procedure SetCellVar(IsVar: Boolean; VarName: string = '');

 

    procedure SetFlagCellMark(Value: UINT; IsClear: Boolean = False);

    procedure SetFlagCellLineColor(Value: TColor);

    procedure SetFlagCellLineWidth(Value: Integer);

 

    procedure SetCellFont(Value: TFont);

    procedure SetCellLogFont(Value: TLogFont);

    procedure SetCellText(Value: string);

    procedure SetCellMarker(Value: UINT; Clear: Boolean = False);

    procedure SetCellHAlign(Value: Integer);

    procedure SetCellVAlign(Value: Integer);

    procedure SetCellTextColor(Value: COLORREF);

    procedure SetCellBackGdColor(Value: COLORREF);

    procedure SetCellPicture(PicFileName: string; ClearPic: Boolean = False);

    procedure SetCellIsPictureEx(Value: Boolean);

    procedure SetCellReadOnly(Value: Boolean);

    procedure SetCellVerticalText(Value: Boolean);

    procedure SetLineHeight(Value: Integer);

 

    function GetCellFont: TFont;

    function GetCellLogFont: TLogFont;

    function GetCellText: string;

    function GetCellMarker: UINT;

    function GetCellHAlign: Integer;

    function GetCellVAlign: Integer;

    function GetCellTextColore: COLORREF;

    function GetCellBackGdColor: COLORREF;

    function GetCellIsPicture: Boolean;

    function GetCellReadOnly: Boolean;

    function GetCellIsPictureEx: Boolean;

    function GetCellVerticalText: Boolean;

    function GetLineHeight: Integer;

 

    {页面参数的设置...}

    procedure SetInchMargin(Left, Top, Right, Bottom: Integer);   //单位:毫米

    procedure SetPixelsMargin(Left, Top, Right, Bottom: Integer); //单位:象素

    function GetMargin: TRect;

 

    {选中区的操作}

    procedure SelectCell(RowNum, ColNum: Integer; ClearExist: Boolean = False);

    procedure SelectLine(LineNum: Integer); {LineNum从1开始}

    procedure RemoveAllSelectedCell;

    function IsAnyCellSelected: Boolean;

 

    Procedure ChangeSelectedLineHeight(Value: Integer);

 

    {变量相关...}

    procedure AddVarItem(VarName, VarValue: string);

    procedure RemoveVarItem(VarName: string);

    procedure ClearVarList;

    Procedure UpdateVarCombobox;

 

    {数据相关的}

    procedure ClearReport;

    procedure ResetReport;

 

    {打印输出相关...}//打印文档名称    是否进行格式化套打

    procedure PrintIt(DocTitle: string; FormatPrint: Boolean = False);

 

    {页码设置}

    property ReportScale: Integer read FReportScale write SetScale default 100;

    property CurrentCell: TReportCell read GetCurrentCell;

    property FlagCell: TReportCell read GetFlagCell;

    property PageHeight: Integer read FPageHeight;

 

    procedure RefreshVarCells;

    procedure DeleteFlagCell;

  published

    property Left;

    property Top;

    property Cursor;

    property Hint;

    property Visible default True;

    property Enabled default True;

 

    property HeaderLineShow: Boolean index 0 read GetHFLineShow write SetHFLineShow;

    property FooterLineShow: Boolean index 1 read GetHFLineShow write SetHFLineShow;

    property HeaderStrings: string index 0 read GetHFStrings write SetHFStrings;

    property FooterStrings: string index 1 read GetHFStrings write SetHFStrings;

 

    property AdjustLineHeight: Integer read FAdjustLineHeight write SetAdjustLineHeight;

    property AutoTableSize: Boolean read FAutoTableSize write FAutoTableSize;

    property LockGrid: Boolean read FLockGrid write SetLockGrid;

    property Editing: Boolean read FEditing write SetEditing;

    property SwithView: Boolean read FSwithView write FSwithView;

    property ReportControls: TControls read FControls write FControls;

    property ReportPrinter: TReportPrinter read FPrinter write FPrinter;

    property StudyEdition: Boolean read FStudyEdition write FStudyEdition;

    property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;

    property OnSelected: TSelectEvent read FOnSelected write FOnSelected;

    property OnClick: TClickEvent read FOnClick write FOnClick;

  end;

 

  {---------------------------------------------------------------------------}

  PMyPaper = ^TMyPaper;

  TMyPaper = record

    PaperName: string;

    PaperMode: DWord;

  end;

 

  TReportPrinter = class(TPersistent)

  private

    FPrinters: TStrings;

    FPrinterPapers: TList;

    FPrinterBins: TStrings;

 

    FCurrentPaper: string;    //当前的纸张类型

    FSupportPaper: TStrings;  //所有支持的纸张类型

 

    FIsBusy: Boolean;

    FReportFairy: TReportFairy;

 

    function GetHandle: THandle; //句柄

    function GetCanvas: TCanvas; //画布

 

    function GetPrinters: TStrings;              //得到当前机器的所有打印机名称

    function GetPrinterIndex: Integer;           //得到当前打印机的序号

    function GetPrinterBins: TStrings;           //得到当前打印机的所有纸张来源

    function GetPrinterBinIndex: Integer;        //得到当前打印机的当前纸张来源

    function GetTitle: string;                   //得到打印标题

    function GetMyDitherType: TMyDitherType;     //得到抖动模式

    function GetMyDuplexType: TMyDuplexType;     //得到双工模式

    function GetMyOrientation: TMyOrientation;   //得到进纸模式

    function GetMyColorType: TMyColorType;       //得到色彩模式

    function GetMyPrintQuality: TMyPrintQuality; //得到打印品质

    function GetMagin(Index: Integer): Integer;  //得到打印边界

 

    function GetPrinterPortNT(PrinterName: PChar): PChar;//得到基于WinNT架构操作系统的打印机的Port

    function GetIndexOf(APrinter: string): Integer;      //APrinter是第几个打印机?

 

    function GetPrinterInstalled: Boolean;//是否安装有打印机

    function GetPrinterSelected: Boolean; //是否有默认打印机

    function GetPrinterHeight: Integer;   //得到打印机当前的打印高度

    function GetPrinterWidth: Integer;    //得到打印机当前的打印宽度

    function GetPageHeight: Integer;      //得到打印机当前的纸张高度

    function GetPageWidth: Integer;       //得到打印机当前的纸张宽度

 

    procedure FreePrinters;               //Free打印机

    procedure UpdatePrinterPapers(NewPrinterIndex: Integer);  //更新当前打印机所支持的所有纸张类型

 

    procedure SetPrinterIndex(Index: Integer);                //设置当前打印机

    procedure SetPrinterBinIndex(Index: Integer);             //设置纸张来源

    procedure SetTitle(ATitle: string);                       //设置打印标题

    procedure SetMyDitherType(ADitherType: TMyDitherType);    //设置抖动模式

    procedure SetMyDuplexType(ADuplexType: TMyDuplexType);    //设置双工模式

    procedure SetMyOrientation(AOrientation: TMyOrientation); //设置进纸模式

    procedure SetMyPrintQuality(AQuality: TMyPrintQuality);   //设置打印品质

    procedure SetMyColorType(AColor: TMyColorType);           //设置色彩模式

    procedure SetMagin(Index, Value: Integer);                //设置页面边距

    procedure SetPaperSize(APapeName: string); //overload;    //设置纸张类型

    //procedure SetPaperSize(APapeMode: DWord);  overload;    //设置纸张类型

  public

    constructor Create(AOwner: TReportFairy);

    destructor Destroy; override;

 

    procedure BeginDoc;                    //开始打印

    procedure EndDoc;                      //结束打印

    procedure Abort;                       //中断打印

    procedure RefreshPrinters;             //刷新打印机设置

 

    procedure ResetPrinter;                //复位打印机

 

    function PrinterPpiX: Integer;         //X方向的PPi

    function PrinterPpiY: Integer;         //Y方向的PPi

 

    property Handle: THandle read GetHandle;

    property Canvas: TCanvas read GetCanvas;

    property PrinterWidth: Integer read GetPrinterWidth;

    property PrinterHeight: Integer read GetPrinterHeight;

 

    property PrinterNames: TStrings read GetPrinters;

    property PrinterSelected: Boolean read GetPrinterSelected;

 

    property IndexOf[Printer: string]: Integer read GetIndexOf;

    property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex;

    property PrinterBins: TStrings read GetPrinterBins;

    property PrinterBinIndex: Integer read GetPrinterBinIndex write SetPrinterBinIndex;

 

    property IsBusy: Boolean read FIsBusy default False;

 

    property Title: string read GetTitle write SetTitle;

 

    property PageHeight: Integer read GetPageHeight;

    property PageWidth: Integer read GetPageWidth;

  published

    property SupportPaper: TStrings read FSupportPaper;

    property CurrentPaper: string read FCurrentPaper write SetPaperSize;

    property ColorType: TMyColorType read GetMyColorType write SetMyColorType;

    property Orientation: TMyOrientation read GetMyOrientation write SetMyOrientation;

    property DitherType: TMyDitherType read GetMyDitherType write SetMyDitherType;

    property DuplexType: TMyDuplexType read GetMyDuplexType write SetMyDuplexType;

    property PrintQuality: TMyPrintQuality read GetMyPrintQuality write SetMyPrintQuality default knMedium;

 

    property PaperLeftMargin: Integer   Index 0 read GetMagin write SetMagin;

    property PaperRightMargin: Integer  Index 1 read GetMagin write SetMagin;

    property PaperTopMargin: Integer    Index 2 read GetMagin write SetMagin;

    property PaperBottomMargin: Integer Index 3 read GetMagin write SetMagin;

  end;

 

 

  {----------------------------------------------------------------------------}

  TTPrinterDevice = class(TObject) {打印设备类、用来存储当前打印机。TReportPrinter类用到,}

  public

    Driver, Device, Port: string; //驱动、设备、端口

    constructor Create(ADriver, ADevice, APort: PChar);

  end;

 

  {----------------------------------------------------------------------------}

  TTVarItem = class(TObject) {设置变量使用}

  public

    VarName: string;

    VarValue: string;

  end;

 

  {----------------------------------------------------------------------------}

  TTCellTable = class(TObject) {在解决 Cell的隶属关系时用到}

  public

    PrevCell: TReportCell;

    ThisCell: TReportCell;

  end;

 

  {----------------------------------------------------------------------------}

  TTMyRect = class(TObject)  {在合并Cell的时候用到}

  public

    Left: Integer;

    Top: Integer;

    Right: Integer;

    Bottom: Integer;

  end;

1.3 ReportCover

1.3.1 说明

制造封面的组件,其大部分原理和第一个组件一样,只是本组件只是用来实现制作封面的,比第一个的使用方法还简单,无需多说,看Demo吧!(在   .\Samples\封面”  目录)

1.3.2 单元声明

                          

unit ReportCover;

 

interface

 

uses

  Windows, Messages, SysUtils, Classes, Controls, Forms, Graphics, Registry,

  Printers, WinSpool, Math, Buttons, StdCtrls, Dialogs, Menus, ReportFunc;

 

const

  {Horz Align}

  ALIGN_LEFT = 0;

  ALIGN_HCENTER = 1;

  ALIGN_RIGHT = 2;

 

  {Vert Align}

  ALIGN_TOP = 0;

  ALIGN_VCENTER = 1;

  ALIGN_BOTTOM = 2;

 

  { 斜线定义}

  LINE_LEFT = 1;     { Left Top to Right Bottom }

  LINE_RIGHT = 2;    { Right Top to Left Bottom }

 

  {常用的打印纸张类型 53种}

  DMPAPER_LETTER         = 1;   { Letter 8 12 x 11 in             }

  DMPAPER_LETTERSMALL    = 2;   { Letter Small 8 12 x 11 in       }

  DMPAPER_TABLOID        = 3;   { Tabloid 11 x 17 in              }

  DMPAPER_LEDGER         = 4;   { Ledger 17 x 11 in               }

  DMPAPER_LEGAL          = 5;   { Legal 8 12 x 14 in              }

  DMPAPER_STATEMENT      = 6;   { Statement 5 12 x 8 12 in        }

  DMPAPER_EXECUTIVE      = 7;   { Executive 7 14 x 10 12 in       }

  DMPAPER_A3             = 8;   { A3 297 x 420 mm                 }

  DMPAPER_A4             = 9;   { A4 210 x 297 mm                 }

  DMPAPER_A4SMALL        = 10;  { A4 Small 210 x 297 mm           }

  DMPAPER_A5             = 11;  { A5 148 x 210 mm                 }

  DMPAPER_B4             = 12;  { B4 (JIS) 250 x 354              }

  DMPAPER_B5             = 13;  { B5 (JIS) 182 x 257 mm           }

  DMPAPER_FOLIO          = 14;  { Folio 8 12 x 13 in              }

  DMPAPER_QUARTO         = 15;  { Quarto 215 x 275 mm             }

  DMPAPER_10X14          = 16;  { 10x14 in                        }

  DMPAPER_11X17          = 17;  { 11x17 in                        }

  DMPAPER_NOTE           = 18;  { Note 8 12 x 11 in               }

  DMPAPER_ENV_9          = 19;  { Envelope #9 3 78 x 8 78         }

  DMPAPER_ENV_10         = 20;  { Envelope #10 4 18 x 9 12        }

  DMPAPER_ENV_11         = 21;  { Envelope #11 4 12 x 10 38       }

  DMPAPER_ENV_12         = 22;  { Envelope #12 4 \276 x 11        }

  DMPAPER_ENV_14         = 23;  { Envelope #14 5 x 11 12          }

  DMPAPER_ENV_DL         = 27;  { Envelope DL 110 x 220mm         }

  DMPAPER_ENV_C5         = 28;  { Envelope C5 162 x 229 mm        }

  DMPAPER_ENV_C3         = 29;  { Envelope C3  324 x 458 mm       }

  DMPAPER_ENV_C4         = 30;  { Envelope C4  229 x 324 mm       }

  DMPAPER_ENV_C6         = 31;  { Envelope C6  114 x 162 mm       }

  DMPAPER_ENV_C65        = 32;  { Envelope C65 114 x 229 mm       }

  DMPAPER_ENV_B4         = 33;  { Envelope B4  250 x 353 mm       }

  DMPAPER_ENV_B5         = 34;  { Envelope B5  176 x 250 mm       }

  DMPAPER_ENV_B6         = 35;  { Envelope B6  176 x 125 mm       }

 

  DMPAPER_9X11           = 44;  { 9 x 11 in                       }

  DMPAPER_10X11          = 45;  { 10 x 11 in                      }

  DMPAPER_15X11          = 46;  { 15 x 11 in                      }

  DMPAPER_LETTER_EXTRA   = 50;  { Letter Extra 9 \275 x 12 in     }

  DMPAPER_LEGAL_EXTRA    = 51;  { Legal Extra 9 \275 x 15 in      }

  DMPAPER_TABLOID_EXTRA  = 52;  { Tabloid Extra 11.69 x 18 in     }

  DMPAPER_A4_EXTRA       = 53;  { A4 Extra 9.27 x 12.69 in        }

  DMPAPER_A4_TRANSVERSE  = 55;  { A4 Transverse 210 x 297 mm      }

  DMPAPER_A5_TRANSVERSE  = 61;  { A5 Transverse 148 x 210 mm      }

  DMPAPER_B5_TRANSVERSE  = 62;  { B5 (JIS) Transverse 182 x 257 mm}

  DMPAPER_A3_TRANSVERSE  = 67;  { A3 Transverse 297 x 420 mm      }

  DMPAPER_PENV_1         = 96;  { PRC Envelope #1 102 x 165 mm    }

  DMPAPER_PENV_2         = 97;  { PRC Envelope #2 102 x 176 mm    }

  DMPAPER_PENV_3         = 98;  { PRC Envelope #3 125 x 176 mm    }

  DMPAPER_PENV_4         = 99;  { PRC Envelope #4 110 x 208 mm    }

  DMPAPER_PENV_5         = 100; { PRC Envelope #5 110 x 220 mm    }

  DMPAPER_PENV_6         = 101; { PRC Envelope #6 120 x 230 mm    }

  DMPAPER_PENV_7         = 102; { PRC Envelope #7 160 x 230 mm    }

  DMPAPER_PENV_8         = 103; { PRC Envelope #8 120 x 309 mm    }

  DMPAPER_PENV_9         = 104; { PRC Envelope #9 229 x 324 mm    }

  DMPAPER_PENV_10        = 105; { PRC Envelope #10 324 x 458 mm   }

 

  { 打印机抖动模式}

  DMDITHER_NONE = 1;      { 不抖动  }

  DMDITHER_COARSE = 2;    { 粗糙画笔模式  }

  DMDITHER_FINE = 3;      { 优秀画笔模式  }

  DMDITHER_LINEART = 4;   { 艺术抖动模式  }

  DMDITHER_GRAYSCALE = 10;{ 灰度抖动模式  }

 

  { 打印机双工模式 }

  DMDUP_SIMPLEX = 1;    { 简单双工模式 }

  DMDUP_VERTICAL = 2;   { 纵向双工模式 }

  DMDUP_HORIZONTAL = 3; { 横向双工模式 }

 

  { 打印机的色彩模式 }

  DMCOLOR_MONOCHROME = 1; { 单色模式 }

  DMCOLOR_COLOR = 2;      { 彩色模式 }

 

  { 打印机打印品质 }

  DMRES_DRAFT = LongWord(-1); { 草图 }

  DMRES_LOW = LongWord(-2);   { 一般 }

  DMRES_MEDIUM = LongWord(-3);{ 中等 }

  DMRES_HIGH = LongWord(-4);  { 优秀 }

 

type

  TReportCell = class;

  TReportCover = class;

  TReportPrinter = class;

 

  PPArray = ^TPArray;

  TPArray = array[0..4] of TPoint;

 

  PPalEntriesArray = ^TPalEntriesArray; {for palette re-construction}

  TPalEntriesArray = array[0..0] of TPaletteEntry;  

 

  TMyDrawType = (knNull, knHoriLine, knVerLine, knEdit, knHTwinEdit, knVTwinEdit, knImage);

                 {空操作  横线        竖线       编辑框   横双编辑框  纵双编辑框   图片   }

 

  {打印机参数}

  TMyOrientation = (knPortrait, knLandscape);

  TMyColorType = (knColor, knMonochrome);

  TMyDuplexType = (knSimplex, knHorzDuplex, knVertDuplex);

  TMyDitherType = (knNone, knCourse, knFine, knLineArt, knGrayScale);

  TMyPrintQuality = (knDraft, knLow, knMedium, knHigh);

 

  {预览参数}

  TMyViewState= (knHundred, knWidth, knHeight);  

 

  TSelectEvent = procedure(IsMenuPop: Boolean; SelCell: TReportCell; Button: TMouseButton; X, Y: Integer) of object;

  {----------------------------------------------------------------------------}

 

 

  TControls = class(TPersistent)

  private

    FReportCover: TReportCover;

 

    FNull      : TSpeedButton;

    FHoriLine  : TSpeedButton;

    FVerLine   : TSpeedButton;

    FEdit      : TSpeedButton;

    FHTwinEdit : TSpeedButton;

    FVTwinEdit : TSpeedButton;

    FImage     : TSpeedButton;

 

    FLeftLine  : TSpeedButton;

    FRightLine : TSpeedButton;

    FTopLine   : TSpeedButton;

    FBottomLine: TSpeedButton;

    FAllLine   : TSpeedButton;

    FLeftDiagonal : TSpeedButton;

    FRightDiagonal: TSpeedButton;

 

    FVarEdit   : TEdit;

    FVarButton : TSpeedButton;

    //FPageNO:    TEdit;  //No Used

    //FFirstPage: TSpeedButton;

    //FPrevPage:  TSpeedButton;

    //FNextPage:  TSpeedButton;

    //FLastpage:  TSpeedButton;

 

    //FAddPage:   TSpeedButton;

    //FDeletePage: TSpeedButton;

 

    FLineWidth: TComboBox;

    FZoomScale: TComboBox;

    procedure SetVarButton(const Value: TSpeedButton);

  protected

    procedure SetDrawType(Index: Integer; Value: TSpeedButton);

    procedure SetShowLine(Index: Integer; Value: TSpeedButton);

    procedure SetDiagonalLine(Index: Integer; Value: TSpeedButton);

    //procedure SetPreviewButton(Index: Integer; Value: TSpeedButton);

    //procedure SetAddDelButton(Index: Integer; Value: TSpeedButton);

    procedure SetLineWidth(Value: TComboBox);

    procedure SetZoomScale(Value: TComboBox);

    //procedure SetPageNO(Value: TEdit);

 

    procedure ZoomScaleChange(Sender: TObject);

    procedure LineWidthChange(Sender: TObject);

    //procedure PageNOChange(Sender: TObject);

 

    procedure LeftLineClick(Sender: TObject);

    procedure RightLineClick(Sender: TObject);

    procedure TopLineClick(Sender: TObject);

    procedure BottomLineClick(Sender: TObject);

    procedure AllLineClick(Sender: TObject);

    procedure LeftDiagonalClick(Sender: TObject);

    procedure RightDiagonalClick(Sender: TObject);

 

    procedure VarButtonClick(Sender: TObject);

 

    //procedure FirstPageClick(Sender: TObject);

    //procedure PrevPageClick(Sender: TObject);

    //procedure NextPageClick(Sender: TObject);

    //procedure LastpageClick(Sender: TObject);

 

    //procedure AddPageClick(Sender: TObject);

    //procedure DeletePageClick(Sender: TObject);

  public

    constructor Create(AOwner: TReportCover);

  published

    property dtNull:      TSpeedButton index 0 read FNull      write SetDrawType;

    property dtHoriLine:  TSpeedButton index 1 read FHoriLine  write SetDrawType;

    property dtVerLine:   TSpeedButton index 2 read FVerLine   write SetDrawType;

    property dtEdit:      TSpeedButton index 3 read FEdit      write SetDrawType;

    property dtHTwinEdit: TSpeedButton index 4 read FHTwinEdit write SetDrawType;

    property dtVTwinEdit: TSpeedButton index 5 read FVTwinEdit write SetDrawType;

    property dtImage:     TSpeedButton index 6 read FImage     write SetDrawType;

 

    property slLeftLine  : TSpeedButton index 0 read FLeftLine   write SetShowLine;

    property slRightLine : TSpeedButton index 1 read FRightLine  write SetShowLine;

    property slTopLine   : TSpeedButton index 2 read FTopLine    write SetShowLine;

    property slBottomLine: TSpeedButton index 3 read FBottomLine write SetShowLine;

    property slAllLine   : TSpeedButton index 4 read FAllLine    write SetShowLine;

 

    property slLeftDiagonal : TSpeedButton index 0 read FLeftDiagonal  write SetDiagonalLine;

    property slRightDiagonal: TSpeedButton index 1 read FRightDiagonal write SetDiagonalLine;

 

    property varEdit : TEdit read FVarEdit  write FVarEdit;

    property varButton: TSpeedButton  read FVarButton write SetVarButton;

 

    //property PageNO:    TEdit  read FPageNO write SetPageNo;

    //property pvPrevPage:  TSpeedButton index 1 read FPrevPage  write SetPreviewButton;

    //property pvNextPage:  TSpeedButton index 2 read FNextPage  write SetPreviewButton;

    //property pvLastpage:  TSpeedButton index 3 read FLastpage  write SetPreviewButton;

    //property pvFirstPage: TSpeedButton index 0 read FFirstPage write SetPreviewButton;

 

    //property pvAddPage: TSpeedButton    index 0 read FAddPage    write SetAddDelButton;

    //property pvDeletePage: TSpeedButton index 1 read FDeletePage write SetAddDelButton;

 

    Property ZoomScale: TComboBox  read FZoomScale write SetZoomScale;

    Property LineWidth: TComboBox  read FLineWidth write SetLineWidth;

  end;

 

  {----------------------------------------------------------------------------}

  TReportCell = class(TObject)

  private

    FOwner: TWinControl;

 

    {size & position}

    FCellLeft: Integer;

    FCellTop: Integer;

    FCellWidth: Integer;

    FCellHeight: Integer;

 

    FCellRect: TRect; // 计算得来

    FTextRect: TRect;

 

    {Border}

    FLeftLine: Boolean;

    FTopLine: Boolean;

    FRightLine: Boolean;

    FBottomLine: Boolean;

    FIsVar: Boolean;

 

    FLineWidth: Integer;

 

    {斜线}

    FDiagonal: UINT;

 

    {Color}

    FLineColor: COLORREF;

    FTextColor: COLORREF;

    FBackGroundColor: COLORREF;

 

    {Align}                         

    FHorzAlign: Integer;

    FVertAlign: Integer;

 

    {String}

    FCellText: string;

 

    {Font}

    FLogFont: TLOGFONT;

 

    {Twins Cell}

    FLeftCell, FRightCell: TReportCell;

    FTopCell, FBottomCell: TReportCell;

 

    {Bitmap}

    FBitmap: TBitmap;

  protected

    function GetColor(Index: Integer): COLORREF;

    function GetLineShow(Index: Integer): Boolean;

    function GetPosition(Index: Integer): Integer;

    function GetSize(Index: Integer): Integer;

    function GetLineWidth: Integer;

 

    procedure SetColor(Index: Integer; Value: COLORREF);

    procedure SetLineShow(Index: Integer; Value: Boolean);

    procedure SetPosition(Index, Value: Integer);

    procedure SetSize(Index, Value: Integer);

    procedure SetLineWidth(Value: Integer);

 

    procedure SetCellText(Value: string);

    procedure SetLogFont(Value: TLOGFONT);

  public

    constructor Create;

    destructor Destroy; override;

 

    procedure CalcCellRect;

 

    procedure PaintCell(hPaintDC: HDC; DefaultText: string = '');

 

    {size & position}

    property CellLeft: Integer index 0 read GetPosition write SetPosition;

    property CellTop: Integer index 1 read GetPosition write SetPosition;

 

    property CellWidth: Integer index 0 read GetSize write SetSize;

    property CellHeight: Integer index 1 read GetSize write SetSize;

 

    property CellRect: TRect read FCellRect;

    property TextRect: TRect read FTextRect;

 

    {Border}

    property LeftLine: Boolean index 0 read GetLineShow write SetLineShow default True;

    property TopLine: Boolean index 1 read GetLineShow write SetLineShow default True;

    property RightLine: Boolean index 2 read GetLineShow write SetLineShow default True;

    property BottomLine: Boolean index 3 read GetLineShow write SetLineShow default True;

 

    property LineWidth: Integer read GetLineWidth write SetLineWidth default 1;

 

    {斜线}

    property Diagonal: UINT read FDiagonal write FDiagonal;

 

    {Color}

    property LineColor: COLORREF index 0 read GetColor write SetColor default clBlack;

    property TextColor: COLORREF index 1 read GetColor write SetColor default clBlack;

    property BkColor: COLORREF index 2 read GetColor write SetColor default clWhite;

 

    {Align}

    property HorzAlign: Integer read FHorzAlign write FHorzAlign default 1;

    property VertAlign: Integer read FVertAlign write FVertAlign default 1;

 

    {String}

    property CellText: string read FCellText write SetCellText;

 

    {Font}

    property LogFont: TLOGFONT read FLogFont write SetLogFont;

 

    {Font}

    property IsVar: Boolean read FIsVar write FIsVar;    

  end;

 

  {----------------------------------------------------------------------------}

  TReportCover = class(TWinControl)

  private

    FAppDir: string;           //Application的Dir

 

    FCellList: TList;         // 存放Cell的List

    FSelectCells: TList;      // 存放选中Cell的List

    FMuliSelect: Boolean;     // 表示是否处于 Ctl键 按下的多选状态

    FEditCell: TReportCell;   // 处于编辑状态的Cell

 

    SelFont: TFont;           // Add 2002.11.14

    FPopupMenu: TPopupMenu;

 

    FBorderFrame: Boolean;    // 显示边框

 

    FHeaderList: TList;       // 页眉链表

    FFooterList: TList;       // 页脚链表

 

    FFileItemList: TList;

    FVarList: TList;

    FVarResultList: TStringList;

 

    FDrawType: TMyDrawType;   // 当前的 要新增加Cell的类型

 

    FViewState: TMyViewState;

    FReportScale: Integer;    // 报表的显示比例

    FPageWidth, FPageHeight: Integer;

 

    FPrinter: TReportPrinter; // 打印机Calss

    FPaperName: string;       // 打印纸张名称

    FOrientation: TMyOrientation;  // 打印机进纸方向

 

    FHeaderLine: Boolean;

    FFooterLine: Boolean;

 

    FReadOnly: Boolean;

 

    FLeftMargin: Integer; //边距  (单位:象素)

    FRightMargin: Integer;

    FTopMargin: Integer;

    FBottomMargin: Integer;

 

    FLeftMargin1: Integer; //边距  (单位:mm)

    FRightMargin1: Integer;

    FTopMargin1: Integer;

    FBottomMargin1: Integer;

 

    FMousePoint: TPoint;

 

    {编辑、颜色及字体}

    FEditWnd: HWND;

    FEditBrush: HBRUSH;

    FEditFont: HFONT;

 

    FControls: TControls;

 

    FCurPageNo: Integer;

    FPageCount: Integer;

 

    {是否学习版本?}

    FStudyEdition: Boolean;

 

    FOnSelected: TSelectEvent;

 

  protected

    procedure CreateWnd; override;

    procedure Notification(Component: TComponent; Operation: TOperation);override;

    procedure BateEdition(hPaintDC: HDC);

 

    {页眉、页脚相关}

    procedure CreateHeaderList;

    procedure CreateFooterList;

    procedure SetHFLine(Index: Integer; Value: Boolean);

    procedure SetHFText(Index: Integer; Value: string);

    procedure SetBorderFrame(const Value: Boolean);

    procedure UpdateHeaderFooterSize; //更新页眉页脚

    procedure AnalyzeTitle(var Title: string; var StrList: TStringList);

    procedure ReadHeaderFooter(IsHeader: Boolean; var TargetStream: TMemoryStream);

    procedure WriteHeaderFooter(IsHeader: Boolean; var TargetStream: TMemoryStream);

    function GetHFLine(Index: Integer): Boolean;

    function GetHFText(Index: Integer): string;

 

    {WIN消息相关}

    procedure WMPaint(var Message: TMessage); message WM_PAINT;

    procedure WMLButtonDown(var Message: TMessage); message WM_LBUTTONDOWN;

    procedure WMLButtonUp(var Message: TMessage); message WM_LBUTTONUP;

    procedure WMRButtonDown(var Message: TMessage); message WM_RBUTTONDOWN;

    procedure WMLButtonDBLClk(var Message: TMessage); message WM_LBUTTONDBLCLK;

    procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE;

    procedure WMContextMenu(var Message: TMessage); message WM_CONTEXTMENU;

    procedure WMCOMMAND(var Message: TMessage); message WM_COMMAND;

    procedure WMCTLColor(var Message: TMessage); message WM_CTLCOLOREDIT;

    procedure WMKeyDown(var Message: TMessage); message WM_KEYDOWN;

    procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;

 

    {由消息触发的一些过程}

    procedure DrawBorderFrame(hPaintDC: HDC);

    procedure SwithViewScale;

    procedure DecorateEditCell;

    //procedure DecorateSelectedCell;

    procedure InitPArrayList(var ArrayList: TList);

    procedure GetMoveCellsBorder(var BorderRect: TRect; bPoint: TPoint);

    procedure StartCellDrag(var Cell: TReportCell; bPoint: TPoint; bHorz: Boolean);

    procedure StartCellsMove(var Cell: TReportCell; bPoint: TPoint);

    procedure StartMouseSelect(Point: TPoint);

 

    {单元格选择相关}

    function CellFromPoint(point: TPoint): TReportCell;

    function IsTheCellSelected(Cell: TReportCell): Boolean;

    function AddSelectedCell(Cell: TReportCell): Boolean;

    function RemoveSelectedCell(Cell: TReportCell): Boolean;

    function GetVarValue(VarName: string): string;

    function GetCurSelCell: TReportCell;

 

    procedure RemoveAllSelectedCell;

    procedure UpdateFControls(Cell: TReportCell);

 

    function IsPointInPage(Point: TPoint): Boolean;

 

    {响应外部SpeedButton的OnClick过程}

    procedure DrawTypeClick(Sender: TObject);

 

    {画Bmp图片过程}

    procedure BltTBitmapAsDib(DestDc: HDC; X, Y, Width, Height: Word; Bmp: TBitmap);

    procedure DrawCellBitmap(hPaintDC: HDC; CellRect: TRect; Bit: TBitmap);

 

    function SaveTempCover(PageNumber: Integer): Boolean; //如果已经存在则True 否则False

    function LoadTempCover(PageNumber: Integer): Boolean; //如果已经存才则True 否则False

 

    function GetResultFileName(PageNo: Integer): string;

 

    {Var}

    function GetVarList: TStringList;

 

    procedure SetPopupMenu(Value: TPopupMenu);

 

    {调整尺寸}

    procedure RegulatePageSize;

 

  public

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

 

    procedure CloseTable(IsFreeAll: Boolean = True);

 

    {显示尺寸相关}

    procedure CalcWndSize(Flag: Boolean);

    procedure SetScale(Value: Integer);

    procedure SetMargin(nLeftMargin, nTopMargin, nRightMargin, nBottomMargin: Integer);

 

    {设置选中Cell的参数}

    procedure SetCellLineColor(Value: COLORREF);

    procedure SetCellBackColor(Value: COLORREF);

    procedure SetCellTextColor(Value: COLORREF);

    procedure SetCellFont(Value: TLogFont);

    procedure SetCellHorzAlign(Value: Integer);

    procedure SetCellLines(bLeftLine, bTopLine, bRightLine, bBottomLine: Boolean; LineWidth: Integer);

 

    {得到选中Cell的外观}

    Function GetCellLineColor: COLORREF;

    Function GetCellBackColor: COLORREF;

    Function GetCellFont: TFont;

    Function GetCellHorzAlign: Integer; //暂时未用到

    Function GetCellVar: string;

 

    {设置相关Cell的外观属性}

    procedure CombineCell(bHorz: Boolean);

    procedure ExplodeCell;

    procedure HorzAlignCell(Value: Integer); //选中的Cell之间的相互对齐 (Horz方向)

    procedure VertAlignCell(Value: Integer); //选中的Cell之间的相互对齐 (Vert方向)

    procedure HorzCellAlign(Value: Integer); //Cell相对于报表的位置对齐 (Horz方向)

    procedure VertCellAlign(Value: Integer); //Cell相对于报表的位置对齐 (Vert方向)

    procedure HorzEqualSpace;  //选中Cell之间的横向等间距

    Procedure VertEqualSpace;  //选中Cell之间的纵向等间距

    procedure MaxCellWidth;

    Procedure MaxCellHeight;

 

    {Set The Cell's Var Value}

    procedure SetCellVar(IsVar: Boolean; ValueName: string = '');

    procedure AddVarItem(VarName, VarValue: string);

    procedure ClearVarList;

 

    {删除、打印、保存及加载}

    procedure DeleteCell;

    procedure PrintIt(DocTitle: string);

    procedure PrintAll(DocTitle: string; Order: Boolean);

 

    function SaveCover(FileName: string): Boolean;

    function LoadCover(FileName: string): Boolean;

 

    function SaveToStream(var Stream: TMemoryStream): Boolean;

    function LoadFromStream(var Stream: TMemoryStream): Boolean;

 

    procedure DeleteTempFiles;

 

 

    {页码设置}           

    procedure FirstPage;

    function PrevPage: Boolean;

    function NextPage: Boolean;

    procedure LastPage;

    function SelectPageNo(PageNo: Integer): Integer;

 

    procedure AddPage;

    procedure DeletePage;

 

    property CurPageNo: Integer read FCurPageNo write FCurPageNo;

    property PageCount: Integer read FPageCount write FPageCount;

    property ResultVarList: TStringList read GetVarList;

    property CurSelCell: TReportCell read GetCurSelCell;

  published

    property BorderFrame: Boolean read FBorderFrame write SetBorderFrame;

    property DrawType: TMyDrawType read FDrawType write FDrawType;

    property HeaderString: string index 0 read GetHFText write SetHFText;

    property FooterString: string index 1 read GetHFText write SetHFText;

    property HeaderLine: Boolean index 0 read GetHFLine write SetHFLine;

    property FooterLine: Boolean index 1 read GetHFLine write SetHFLine;

    property ReportPrinter: TReportPrinter read FPrinter write FPrinter;

    property ReportControl: TControls read FControls write FControls;

    property ReadOnly: Boolean read FReadOnly write FReadOnly;    

    property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;

    property OnSelected: TSelectEvent read FOnSelected write FOnSelected;    

    property StudyEdition: Boolean read FStudyEdition write FStudyEdition;

  end;

 

 

  {---------------------------------------------------------------------------}

  PMyPaper = ^TMyPaper;

  TMyPaper = record

    PaperName: string;

    PaperMode: DWord;

  end;

 

  TReportPrinter = class(TPersistent)

  private

    FPrinters: TStrings;

    FPrinterPapers: TList;

    FPrinterBins: TStrings;

 

    FCurrentPaper: string;   //当前的纸张类型

    FSupportPaper: TStrings; //所有支持的纸张类型

 

    FIsBusy: Boolean;

    FReportCover: TReportCover;

 

    function GetHandle: THandle; //句柄

    function GetCanvas: TCanvas; //画布

 

    function GetPrinters: TStrings;             //得到当前机器的所有打印机名称

    function GetPrinterIndex: Integer;          //得到当前打印机的序号

    function GetPrinterBins: TStrings;          //得到当前打印机的所有纸张来源

    function GetPrinterBinIndex: Integer;       //得到当前打印机的当前纸张来源

    function GetTitle: string;                  //得到打印标题

    function GetMyDitherType: TMyDitherType;    //得到抖动模式

    function GetMyDuplexType: TMyDuplexType;    //得到双工模式

    function GetMyOrientation: TMyOrientation;  //得到进纸模式

    function GetMyColorType: TMyColorType;      //得到色彩模式

    function GetMyPrintQuality: TMyPrintQuality;//得到打印品质

    function GetMagin(Index: Integer): Integer; //得到打印边界

 

    function GetPrinterPortNT(PrinterName: PChar): PChar; //得到基于WinNT架构操作系统的打印机的Port

    function GetIndexOf(APrinter: string): Integer; //APrinter是第几个打印机?

 

    function GetPrinterInstalled: Boolean; //是否安装有打印机

    function GetPrinterSelected: Boolean;  //是否有默认打印机

    function GetPrinterHeight: Integer;    //得到打印机当前的打印高度

    function GetPrinterWidth: Integer;     //得到打印机当前的打印宽度

    function GetPageHeight: Integer;       //得到打印机当前的纸张高度

    function GetPageWidth: Integer;        //得到打印机当前的纸张宽度

 

    procedure FreePrinters;                //Free打印机

    procedure UpdatePrinterPapers(NewPrinterIndex: Integer);   //更新当前打印机所支持的所有纸张类型

 

    procedure SetPrinterIndex(Index: Integer);                 //设置当前打印机

    procedure SetPrinterBinIndex(Index: Integer);              //设置纸张来源

    procedure SetTitle(ATitle: string);                        //设置打印标题

    procedure SetMyDitherType(ADitherType: TMyDitherType);     //设置抖动模式

    procedure SetMyDuplexType(ADuplexType: TMyDuplexType);     //设置双工模式

    procedure SetMyOrientation(AOrientation: TMyOrientation);  //设置进纸模式

    procedure SetMyPrintQuality(AQuality: TMyPrintQuality);    //设置打印品质

    procedure SetMyColorType(AColor: TMyColorType);            //设置色彩模式

    procedure SetMagin(Index, Value: Integer);                 //设置页面边距

    procedure SetPaperSize(APapeName: string); //overload;     //设置纸张类型

    //procedure SetPaperSize(APapeMode: DWord);  overload;     //设置纸张类型

  public

    constructor Create(AOwner: TReportCover);

    destructor Destroy; override;

 

    procedure BeginDoc; //开始打印

    procedure EndDoc;   //结束打印

    procedure Abort;    //中断打印

    procedure RefreshPrinters; //刷新打印机设置

 

    procedure ResetPrinter;    //复位打印机

 

    function PrinterPpiX: Integer; //X方向的PPi

    function PrinterPpiY: Integer; //Y方向的PPi

 

    property Handle: THandle read GetHandle;

    property Canvas: TCanvas read GetCanvas;

    property PrinterWidth: Integer read GetPrinterWidth;

    property PrinterHeight: Integer read GetPrinterHeight;

 

    property PrinterNames: TStrings read GetPrinters;

    property PrinterSelected: Boolean read GetPrinterSelected;

 

    property IndexOf[Printer: string]: Integer read GetIndexOf;

    property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex;

    property PrinterBins: TStrings read GetPrinterBins;

    property PrinterBinIndex: Integer read GetPrinterBinIndex write SetPrinterBinIndex;

 

    property IsBusy: Boolean read FIsBusy default False;

 

    property PageHeight: Integer read GetPageHeight;

    property PageWidth: Integer read GetPageWidth;

 

    property Title: string read GetTitle write SetTitle;

  published

    property SupportPaper: TStrings read FSupportPaper;

    property CurrentPaper: string read FCurrentPaper write SetPaperSize;

    property ColorType: TMyColorType read GetMyColorType write SetMyColorType;

    property Orientation: TMyOrientation read GetMyOrientation write SetMyOrientation;

    property DitherType: TMyDitherType read GetMyDitherType write SetMyDitherType;

    property DuplexType: TMyDuplexType read GetMyDuplexType write SetMyDuplexType;

    property PrintQuality: TMyPrintQuality read GetMyPrintQuality write SetMyPrintQuality default knMedium;

 

    property PaperLeftMargin: Integer index 0 read GetMagin write SetMagin;

    property PaperRightMargin: Integer index 1 read GetMagin write SetMagin;

    property PaperTopMargin: Integer index 2 read GetMagin write SetMagin;

    property PaperBottomMargin: Integer index 3 read GetMagin write SetMagin;

  end;

 

 

  {打印设备类、用来存储当前打印机。TReportPrinter类用到,}

  TTPrinterDevice = class(TObject)

  public

    Driver, Device, Port: PChar; //驱动、设备、端口

    constructor Create(ADriver, ADevice, APort: PChar);

  end;

 

  {为 临时文件的序列 随机产生文件名}

  TTFileItem = class(TObject)

  public

    Index: Integer;

    FileName: string;

  end;

 

  {设置变量使用}

  TTVarItem = class(TObject)

  public

    VarName: string;

    VarValue: string;

  end;

 【实例截图】

from clipboard
【核心代码】

.
├── KingReport
│   ├── BPL
│   │   ├── KingReport.bpl
│   │   ├── KingReport.dcp
│   │   └── KingReport.map
│   ├── ReadMe.txt
│   ├── Samples
│   │   ├── 封面
│   │   │   ├── Main.dcu
│   │   │   ├── Main.ddp
│   │   │   ├── Main.dfm
│   │   │   ├── Main.pas
│   │   │   ├── PCover.cfg
│   │   │   ├── PCover.dof
│   │   │   ├── PCover.dpr
│   │   │   ├── PCover.drc
│   │   │   ├── PCover.dsk
│   │   │   ├── PCover.exe
│   │   │   ├── PCover.map
│   │   │   ├── PCover.res
│   │   │   ├── ReportDesign.dcu
│   │   │   ├── ReportDesign.ddp
│   │   │   ├── ReportDesign.dfm
│   │   │   ├── ReportDesign.pas
│   │   │   ├── ReportTemp
│   │   │   └── SampleBmp.bmp
│   │   ├── 报表
│   │   │   ├── Data
│   │   │   │   └── DemoDB.DB
│   │   │   ├── GenFunc.dcu
│   │   │   ├── GenFunc.pas
│   │   │   ├── Main.dcu
│   │   │   ├── Main.ddp
│   │   │   ├── Main.dfm
│   │   │   ├── Main.pas
│   │   │   ├── PReport.cfg
│   │   │   ├── PReport.dof
│   │   │   ├── PReport.dpr
│   │   │   ├── PReport.drc
│   │   │   ├── PReport.dsk
│   │   │   ├── PReport.exe
│   │   │   ├── PReport.map
│   │   │   ├── PReport.res
│   │   │   ├── ReadMe.txt
│   │   │   ├── qtintf.dll
│   │   │   └── 模板
│   │   │       └── 模板1
│   │   └── 表格
│   │       ├── Bmp.bmp
│   │       ├── Main.dcu
│   │       ├── Main.ddp
│   │       ├── Main.dfm
│   │       ├── Main.pas
│   │       ├── NewTable.dcu
│   │       ├── NewTable.ddp
│   │       ├── NewTable.dfm
│   │       ├── NewTable.pas
│   │       ├── PTable.cfg
│   │       ├── PTable.dof
│   │       ├── PTable.dpr
│   │       ├── PTable.dsk
│   │       ├── PTable.exe
│   │       ├── PTable.res
│   │       ├── ScratchD6.dll
│   │       ├── SetPrinter.dcu
│   │       ├── SetPrinter.ddp
│   │       ├── SetPrinter.dfm
│   │       └── SetPrinter.pas
│   ├── Source
│   │   ├── BoolComboBox.pas
│   │   ├── CoverCursor.RES
│   │   ├── FairyCursor.RES
│   │   ├── KingReport.cfg
│   │   ├── KingReport.dcu
│   │   ├── KingReport.dof
│   │   ├── KingReport.dpk
│   │   ├── KingReport.drc
│   │   ├── KingReport.dsk
│   │   ├── KingReport.res
│   │   ├── MasterCursor.RES
│   │   ├── MyColorBox.dcu
│   │   ├── MyColorBox.pas
│   │   ├── MyZip.pas
│   │   ├── ReportCover.dcu
│   │   ├── ReportCover.pas
│   │   ├── ReportDesign.dcu
│   │   ├── ReportDesign.ddp
│   │   ├── ReportDesign.dfm
│   │   ├── ReportDesign.pas
│   │   ├── ReportFairy.dcu
│   │   ├── ReportFairy.pas
│   │   ├── ReportFunc.dcu
│   │   ├── ReportFunc.pas
│   │   ├── ReportMaster.dcu
│   │   ├── ReportMaster.pas
│   │   ├── ReportReg.dcu
│   │   └── ReportReg.pas
│   ├── Tools
│   │   ├── DBField.dcu
│   │   ├── DBField.ddp
│   │   ├── DBField.dfm
│   │   ├── DBField.pas
│   │   ├── Main.dcu
│   │   ├── Main.ddp
│   │   ├── Main.dfm
│   │   ├── Main.pas
│   │   ├── PDesign.cfg
│   │   ├── PDesign.dof
│   │   ├── PDesign.dpr
│   │   ├── PDesign.drc
│   │   ├── PDesign.dsk
│   │   ├── PDesign.exe
│   │   ├── PDesign.map
│   │   ├── PDesign.res
│   │   └── 模板
│   │       └── Test.txt
│   └── 报表文档.doc
└── 好例子网_KingReport.zip

12 directories, 106 files





实例下载地址

KingReport报表控件

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警