project1.dll如下:<br>================================================================================<br>library Project1;<br><br>uses<br> Forms,<br> PrintForm in 'PrintForm.pas' {frmPrintForm};<br><br>Exports<br> WinPrint;<br>{$R *.res}<br><br><br>begin<br>{ Application.Initialize;<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>}<br>end.<br>------------------------------------------------------------------------------<br>unit PrintForm;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> dxDBGrid, RM_class, RM_Desgn, RM_dset, RM_dbset, dxEditor, StdCtrls,<br> dxCntner, dxEdLib, dxDBELib, dxTL, dxDBCtrl, ExtCtrls, dxExEdtr, RM_shape,<br> dxDBTL, KsSkinLabels, RM_e_csv, RM_e_txt, RM_chart, RM_FormReport, Series;<br><br>const<br> SHOW_REPORT = 1;<br> PRINT_REPORT = 2;<br> DESIGN_REPORT = 3;<br> INITI_REPORT = 4;<br><br>type<br> TfrmPrintForm = class(TForm)<br> rmReport: TRMReport;<br> RMDesigner1: TRMDesigner;<br> RMDBDataSet1: TRMDBDataSet;<br> RMTextExport1: TRMTextExport;<br> RMCSVExport1: TRMCSVExport;<br> RMChartObject1: TRMChartObject;<br> RMChartObject2: TRMChartObject;<br> private<br> { Private declarations }<br> BandReportTitle: TRMBandView;<br> BandPageHeader: TRMBandView;<br> BandDetail: TRMBandView;<br> BandDetailChart: TRMBandView;<br> BandPageFooter: TRMBandView;<br> BandReportSummary: TRMBandView;<br><br> lTitleY, lGridY, lGridH: Integer;<br> frmForm1: TForm;<br> Page1: TRMPage;<br> sReportFile, sFile: string;<br> lTitle, lMode: Integer;<br> bPrintBar, bReturn, bNewReport: Boolean;<br> lPrintChartType: Integer;<br> sChart, sPrintChartX, sPrintChartY, sChartNameX, sChartNameY: string;<br> procedure PrintPrepare; //准备打印<br> function PrintBegin: Boolean; //开始打印<br><br> procedure LoadBand; //读入页边条<br> procedure LoadControl(Control: TControl); //读入Control<br> procedure LoadTopControl(Control: TControl); //读入最上面Control<br> procedure LoadBottomControl(Control: TControl); //读入最下面Control<br> procedure LoadOldControl(Control: TControl); //读入已存在Control<br><br> procedure LoadDBGrid(Grid1: TdxDBGrid); //读入DBGrid<br> procedure SetGridHeader(Grid1: TdxDBGrid); //设置表头<br> procedure SetGridBody(Grid1: TdxDBGrid); //设置表体<br> procedure SetGridSummary(Grid1: TdxDBGrid); //设置表尾<br><br> procedure LoadDBTree(Tree1: TdxDBTreeList); //读入DBTree<br> procedure SetTreeHeader(Tree1: TdxDBTreeList); //设置表头<br> procedure SetTreeBody(Tree1: TdxDBTreeList); //设置表体<br> procedure SetTreeSummary(Tree1: TdxDBTreeList); //设置表尾<br><br> function LoadReportFile: Boolean; //读报表文件<br> function SaveReportFile: boolean; //写报表文件<br><br> procedure SetTitle; //设置标题<br> function GetAlignment(Align: TAlignment): TRMAlignment;<br> function GetBandSub(Grid1: TCustomdxDBTreeListControl; Index: Integer):<br> Integer;<br> function ViewAssign(m1: TRMMemoView; Control: TControl): Boolean;<br> //为各种控件赋值<br> function ShapeViewAssign(s1: TRMShapeView; Control: TControl): Boolean;<br> //为各种Shape控件赋值<br> function PicViewAssign(p1: TRMPictureView; Control: TControl): Boolean;<br> //为各种图象控件赋值<br> function GetPoint(Control: TControl): TPoint;<br> procedure SetChart;<br> public<br> { Public declarations }<br> end;<br><br>function WinPrint(Form1: TForm; lTitle1, lMode1: Integer; sFile1, sChart1:<br> string): Boolean;<br>{<br> 参数( 要打印Form;标题类型(0=空,1=中间,2=左边);打印类型(显示,打印,编辑,初始化);文件ID )<br> 打印类型(显示=SHOW_REPORT,打印=PRINT_REPORT,编辑=DESIGN_REPORT,初始化=INITI_REPORT)<br>}<br>implementation<br><br>{$R *.DFM}<br>const<br> C_LEFT = 20;<br> C_HEIGHT = 20;<br><br>function WinPrint(Form1: TForm; lTitle1, lMode1: Integer; sFile1, sChart1:<br> string): Boolean;<br>var<br> frmPrintForm: TfrmPrintForm;<br>begin<br> frmPrintForm := TfrmPrintForm.Create(Application);<br> with frmPrintForm do<br> begin<br> frmForm1 := Form1;<br> lMode := lMode1;<br> lTitle := lTitle1;<br> sFile := sFile1;<br> sChart := sChart1;<br> PrintPrepare;<br> PrintBegin;<br> Result := bReturn;<br> {Free;}<br> end;<br>end;<br><br>procedure TfrmPrintForm.PrintPrepare;<br>var<br> i: Integer;<br>begin<br><br> lPrintChartType := -1;<br> sPrintChartX := '';<br> sPrintChartY := '';<br> sChartNameX := '';<br> sChartNameY := '';<br><br> if (sPrintChartX = '') or (sPrintChartY = '') then<br> lPrintChartType := -1; //不是图形<br> if lPrintChartType >= 0 then<br> bNewReport := True;<br><br> LoadReportFile; //装载报表文件<br> LoadBand; //装载条带<br> SetTitle;<br> with frmForm1 do<br> begin<br> for i := 0 to ComponentCount - 1 do<br> begin<br> if (TControl(Components).Visible) and (Components is<br> TCustomdxTreeList) then<br> begin<br> lGridY := GetPoint(TControl(Components)).Y;<br> lGridH := TdxDBGrid(Components).RowHeight;<br> end;<br> end;<br> for i := 0 to ComponentCount - 1 do<br> if (TControl(Components).Visible) and (Components is TControl) then<br> begin<br> if bNewReport then<br> LoadTopControl(TControl(Components))<br> else<br> LoadOldControl(TControl(Components));<br> end;<br> for i := 0 to ComponentCount - 1 do<br> if (TControl(Components).Visible) and (Components is TdxDBGrid) then<br> LoadDBGrid(TdxDBGrid(Components)); //装载报表数据源<br> for i := 0 to ComponentCount - 1 do<br> if (TControl(Components).Visible) and (Components is TdxDBTreeList) then<br> LoadDBTree(TdxDBTreeList(Components));<br> for i := 0 to ComponentCount - 1 do<br> begin<br> if (TControl(Components).Visible) and (Components is TControl) then<br> begin<br> if bNewReport then<br> LoadBottomControl(TControl(Components))<br> else<br> LoadOldControl(TControl(Components));<br> end;<br> end;<br> if bNewReport then<br> for i := 0 to ComponentCount - 1 do<br> begin<br> if (sChartNameX <> '') and (sChartNameY <> '') then<br> begin<br> SetChart;<br> Break;<br> end;<br> end;<br> end;<br>end;<br><br>procedure TfrmPrintForm.SetChart;<br>var<br> lBY, lBH: Integer;<br> cv: TRMChartView;<br>begin<br> //饼图<br> BandPageHeader.Visible := False;<br> BandDetail.dy := 0;<br> BandReportSummary.Visible := False;<br> lBY := BandReportSummary.y + BandReportSummary.dy + C_HEIGHT;<br> lBH := 300;<br> BandDetailChart := TRMBandView(RMCreateObject(gtBand, ''));<br> BandDetailChart.BandType := btMasterData;<br> BandDetailChart.Name := 'BandDetailChart';<br> Page1.Objects.Add(BandDetailChart);<br> BandDetailChart.SetBounds(0, lBY, 0, lBH);<br> {$IFNDEF NoRmComPass}<br> cv := TRMChartView.Create;<br> cv.Name := 'ChartView';<br> cv.SetBounds(C_LEFT, lBy + C_HEIGHT, 600, lBH - C_HEIGHT);<br> cv.AddSeries;<br> cv.Series[0].ChartOptions.ShowMarks := True;<br> cv.Series[0].ChartOptions.Colored := True;<br> cv.Series[0].ChartOptions.ChartType := lPrintChartType;<br> cv.Series[0].ChartOptions.MarksStyle := 3;<br> cv.Series[0].LegendObj := sChartNameX;<br> cv.Series[0].ValueObj := sChartNameY;<br> Page1.Objects.Add(cv);<br> {$ELSE}<br><br> {$ENDIF}<br>end;<br><br>function TfrmPrintForm.PrintBegin: Boolean;<br>begin<br> Result := True;<br> case lMode of<br> SHOW_REPORT: rmReport.ShowReport;<br> PRINT_REPORT: rmReport.PrintReport;<br> DESIGN_REPORT: rmReport.DesignReport;<br> INITI_REPORT: rmReport.DesignReport;<br> else<br> Result := False;<br> end;<br> if Result <> False then<br> SaveReportFile;<br>end;<br><br>procedure TfrmPrintForm.LoadBand;<br>begin<br> if bNewReport then //如果是新建报表。<br> begin<br> rmReport.Pages.Clear;<br> rmReport.Pages.Add;<br> Page1 := rmReport.Pages[0];<br> BandReportTitle := TRMBandView(RMCreateObject(gtBand, ''));<br> BandReportTitle.BandType := btReportTitle;<br> BandReportTitle.Name := 'BandReportTitle';<br> BandReportTitle.SetBounds(0, C_HEIGHT, 0, 0);<br> Page1.Objects.Add(BandReportTitle);<br><br> BandPageHeader := TRMBandView(RMCreateObject(gtBand, ''));<br> BandPageHeader.BandType := btPageHeader;<br> BandPageHeader.Name := 'BandPageHeader';<br> Page1.Objects.Add(BandPageHeader);<br> BandPageHeader.SetBounds(0, C_HEIGHT * 2, 0, 0);<br><br> BandDetail := TRMBandView(RMCreateObject(gtBand, ''));<br> BandDetail.BandType := btMasterData;<br> BandDetail.Name := 'BandDetail';<br> Page1.Objects.Add(BandDetail);<br> BandDetail.SetBounds(0, C_HEIGHT * 3, 0, 0);<br><br> BandPageFooter := TRMBandView(RMCreateObject(gtBand, ''));<br> BandPageFooter.BandType := btPageFooter;<br> BandPageFooter.Name := 'BandPageFooter';<br> Page1.Objects.Add(BandPageFooter);<br> BandPageFooter.SetBounds(0, C_HEIGHT * 4, 0, 0);<br><br> BandReportSummary := TRMBandView(RMCreateObject(gtBand, ''));<br> BandReportSummary.BandType := btReportSummary;<br> BandReportSummary.Name := 'BandReportSummary';<br> Page1.Objects.Add(BandReportSummary);<br> BandReportSummary.SetBounds(0, C_HEIGHT * 5, 0, 0);<br> end<br> else //如果报表已经存在<br> begin<br> Page1 := rmReport.Pages[0];<br> BandReportTitle := TRMBandView(page1.FindObject('BandReportTitle')); //获取报表标题<br> BandPageHeader := TRMBandView(page1.FindObject('BandPageHeader')); //获取页头<br> BandDetail := TRMBandView(page1.FindObject('BandDetail')); //获取数据区<br> BandPageFooter := TRMBandView(page1.FindObject('BandPageFooter')); //获取页脚<br> BandReportSummary := TRMBandView(page1.FindObject('BandReportSummary')); //获取页合计<br> end;<br>end;<br><br>function TfrmPrintForm.LoadReportFile: Boolean;<br>var<br> sDir: string;<br>begin<br> Result := True;<br> bNewReport := False;<br> sReportFile := '';<br> sDir := Trim(ExtractFilePath(Application.ExeName)) + 'Report';<br> if not DirectoryExists(sDir) then<br> begin<br> if not CreateDir(sDir) then<br> begin<br> raise Exception.Create('不能新建目录,请手工新建这目录。' + #13 + sDir);<br> Result := false;<br> end;<br> end;<br> if Result <> False then<br> begin<br> if lPrintChartType = -1 then<br> sReportFile := sDir + '/' + sFile + '.Rep'<br> else<br> sReportFile := sDir + '/' + sFile + '图形.Rep';<br> end;<br> if (not FileExists(sReportFile)) or (lMode = INITI_REPORT) then<br> bNewReport := True<br> else<br> if not rmReport.LoadFromFile(sReportFile) then<br> bNewReport := True;<br> rmReport.FileName := sReportFile;<br>end;<br><br>function TfrmPrintForm.SaveReportFile: Boolean;<br>begin<br> Result := True;<br> if lPrintChartType >= 0 then<br> Exit;<br> if (sReportFile <> '') and bNewReport then<br> rmReport.SaveToFile(sReportFile);<br> if not FileExists(sReportFile) then<br> Result := False;<br>end;<br><br>procedure TfrmPrintForm.SetTitle;<br>var<br> mt: TRMMemoView;<br> Font: TFont;<br>begin<br> if not bNewReport then //如果不是新建报表,则不必设定报表标题<br> exit;<br> mt := TRMMemoView(RMCreateObject(gtMemo, ''));<br> mt.gapx := 0;<br> mt.gapy := 0;<br> mt.dx := 0;<br> lTitleY := C_HEIGHT;<br> lGridY := 0;<br> if lTitle > 0 then<br> begin<br> Font := TFont.Create;<br> Font.Name := '宋体';<br> Font.Size := 22;<br> Font.Charset := GB2312_CHARSET;<br> Font.Style := [fsBold];<br> mt.Font.Assign(Font);<br> if lTitle = 1 then<br> mt.PAlignment := rmtaCenterJustify<br> else<br> if lTitle = 2 then<br> mt.PAlignment := rmtaLeftJustify;<br> mt.Memo.Add(frmForm1.Caption);<br> mt.SetBounds(C_LEFT, C_HEIGHT, frmForm1.Width, 40);<br> mt.Name := 'TiTtle' + frmForm1.Name;<br> Page1.Objects.Add(mt);<br> BandReportTitle.y := C_HEIGHT;<br> BandReportTitle.dy := 40;<br> lTitleY := BandReportTitle.dy + C_HEIGHT;<br> end<br>end;<br><br>procedure TfrmPrintForm.LoadControl(Control: TControl);<br>var<br> m: TRMMemoView;<br> p: TRMPictureView;<br> s: TRMShapeView;<br>begin<br> if Control.Parent.Visible = False then<br> exit;<br> if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is<br> TdxDBGraphicEdit) then<br> begin<br> p := TRMPictureView(RMCreateObject(gtPicture, ''));<br> p.gapx := 0;<br> p.gapy := 0;<br> p.dx := 0;<br> p.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,<br> Control.Width, Control.Height);<br> if not PicViewAssign(p, Control) then<br> exit;<br> p.Name := Control.Name;<br> Page1.Objects.Add(p);<br> if (BandReportTitle.dy < (p.y + p.dy)) and (p.y < (lGridY + lTitleY)) then<br> BandReportTitle.dy := p.y + p.dy;<br> if p.y > (lGridY + lTitleY) then<br> begin<br> p.y := BandReportSummary.y + lGridH + 8;<br> if (BandReportSummary.dy < (p.y - BandReportSummary.y + p.dy)) then<br> BandReportSummary.dy := (p.y - BandReportSummary.y + p.dy);<br> end;<br> end<br> else<br> if (Control is TShape) then<br> begin<br> s := TRMShapeView(RMCreateObject(gtAddin, 'TRMShapeView'));<br> s.gapx := 0;<br> s.gapy := 0;<br> s.dx := 0;<br> s.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,<br> Control.Width, Control.Height);<br> if not ShapeViewAssign(s, Control) then<br> exit;<br> s.Name := Control.Name;<br> Page1.Objects.Add(s);<br> if (BandReportTitle.dy < (s.y + s.dy)) and (s.y < (lGridY + lTitleY)) then<br> BandReportTitle.dy := s.y + s.dy;<br> if s.y > (lGridY + lTitleY) then<br> begin<br> s.y := BandReportSummary.y + lGridH + 8;<br> if (BandReportSummary.dy < (s.y - BandReportSummary.y + s.dy)) then<br> BandReportSummary.dy := (s.y - BandReportSummary.y + s.dy);<br> end;<br> end<br> else<br> begin<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> m.gapx := 0;<br> m.gapy := 0;<br> m.dx := 0;<br> m.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,<br> Control.Width, Control.Height);<br> if not ViewAssign(m, Control) then<br> exit;<br> m.Name := Control.Name;<br> Page1.Objects.Add(m);<br> if (BandReportTitle.dy < (m.y + m.dy)) and (m.y < (lGridY + lTitleY)) then<br> BandReportTitle.dy := m.y + m.dy;<br> if m.y > (lGridY + lTitleY) then<br> begin<br> m.y := BandReportSummary.y + lGridH + 8;<br> if (BandReportSummary.dy < (m.y - BandReportSummary.y + m.dy)) then<br> BandReportSummary.dy := (m.y - BandReportSummary.y + m.dy);<br> end;<br> end;<br>end;<br><br>procedure TfrmPrintForm.LoadTopControl(Control: TControl); //读入最上面Control<br>begin<br> BandReportSummary.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT * 4;<br> if GetPoint(Control).y <= lGridY then<br> LoadControl(Control);<br>end;<br><br>procedure TfrmPrintForm.LoadBottomControl(Control: TControl); //读入最下面Control<br>begin<br> if GetPoint(Control).y >= lGridY then<br> LoadControl(Control);<br>end;<br><br>procedure TfrmPrintForm.LoadOldControl(Control: TControl);<br>var<br> v: TRMView;<br>begin<br> v := Page1.FindObject(Control.Name);<br> if v = nil then<br> exit;<br> if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is<br> TdxDBGraphicEdit) then<br> begin<br> if not PicViewAssign(TRMPictureView(v), Control) then<br> exit;<br> end<br> else<br> if (Control is TShape) then<br> begin<br> if not ShapeViewAssign(TRMShapeView(Page1.FindObject(Control.Name)), Control) then<br> exit;<br> end<br> else<br> begin<br> if not ViewAssign(TRMMemoView(Page1.FindObject(Control.Name)), Control) then<br> exit;<br> end;<br>end;<br><br>function TfrmPrintForm.GetBandSub(Grid1: TCustomdxDBTreeListControl; Index:<br> Integer): Integer;<br>var<br> i, j: Integer;<br>begin<br> j := 0;<br> for i := 0 to Grid1.ColumnCount - 1 do<br> if Grid1.Columns.Visible and (Grid1.Columns.BandIndex = Index) then<br> inc(j);<br> Result := j;<br>end;<br><br>procedure TfrmPrintForm.LoadDBGrid(Grid1: TdxDBGrid);<br>begin<br> if (Grid1 = nil) or (Grid1.Datasource = nil) or (Grid1.Datasource.Dataset =<br> nil) then<br> Exit;<br> if not Grid1.Datasource.Dataset.Active then<br> Exit;<br> RMDBDataSet1.DataSource := Grid1.DataSource;<br> rmReport.DataSet := RMDBDataSet1;<br> if Grid1.Tag = 5 then<br> bPrintBar := True<br> else<br> bPrintBar := False;<br> SetGridHeader(Grid1); //表头<br> SetGridBody(Grid1); //表体<br> SetGridSummary(Grid1); //表尾<br>end;<br><br>procedure TfrmPrintForm.SetGridHeader(Grid1: TdxDBGrid);<br>var<br> x, i: Integer;<br> m: TRMMemoView;<br>begin<br> if bNewReport then<br> BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;<br> if Grid1.ShowBands then //表头1<br> begin<br> x := C_LEFT;<br> if bNewReport then<br> BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;<br> if bNewReport and bPrintBar then<br> BandPageHeader.dy := 0; //打印成条行表<br> for i := 0 to Grid1.Bands.Count - 1 do<br> begin<br> if not Grid1.Bands.Visible then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> m.SetBounds(x, BandPageHeader.y, Grid1.Bands.Width +<br> GetBandSub(Grid1, Grid1.Bands.Index), Grid1.RowHeight + 4);<br> m.Font.Assign(Grid1.BandFont);<br> m.Memo.Text := Grid1.Bands.Caption;<br> m.PLayout := rmtlCenter;<br> m.PAlignment := GetAlignment(Grid1.Columns.HeaderAlignment); //GetAlignment(Grid1.Columns.Alignment);<br> m.FillColor := Grid1.Color;<br>// m.Font := Grid1.HeaderFont;<br> if Grid1.ShowGrid then<br> m.Prop['FrameTyp'] := $F;<br> m.Name := 'Grid_Band_' + IntToStr(i);<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Grid1.Bands.Width + GetBandSub(Grid1, Grid1.Bands.Index);<br> end;<br> end;<br> if Grid1.ShowHeader then //表头2<br> begin<br> x := C_LEFT;<br> if bNewReport then<br> BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;<br> if bNewReport and bPrintBar then<br> BandPageHeader.dy := 0; //打印成条行表<br> for i := 0 to Grid1.ColumnCount - 1 do<br> begin<br> if not Grid1.Columns.Visible then<br> Continue;<br> if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false) then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> if Grid1.ShowBands then<br> m.SetBounds(x, BandPageHeader.y + Grid1.RowHeight + 4,<br> Grid1.Columns.Width + 1, Grid1.RowHeight + 4)<br> else<br> m.SetBounds(x, BandPageHeader.y, Grid1.Columns.Width + 1,<br> Grid1.RowHeight + 4);<br> m.Font.Assign(Grid1.Columns.Font);<br> m.Memo.Text := Grid1.Columns.Caption;<br> m.PLayout := rmtlCenter;<br> m.PAlignment := GetAlignment(Grid1.Columns.HeaderAlignment); //GetAlignment(Grid1.Columns.Alignment);<br> m.FillColor := Grid1.Color;<br>// m.Font := Grid1.HeaderFont;<br> if Grid1.ShowGrid then<br> m.Prop['FrameTyp'] := $F;<br> m.Name := 'Row0' + Grid1.Columns.Name;<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Grid1.Columns.Width + 1;<br> end;<br> end;<br>end;<br><br>procedure TfrmPrintForm.SetGridBody(Grid1: TdxDBGrid);<br>var<br> x, i: Integer;<br> v: TRMView;<br>begin<br> //画出表体<br> if bNewReport then<br> BandDetail.y := BandPageHeader.y + BandPageHeader.dy + C_HEIGHT;<br> if bNewReport then<br> BandDetail.dy := Grid1.RowHeight + 4;<br><br> x := C_LEFT;<br> for i := 0 to Grid1.ColumnCount - 1 do<br> begin<br> if not Grid1.Columns.Visible then<br> Continue;<br> if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false) then Continue;<br> v := RMCreateObject(gtMemo, '');<br><br> //按表单上表格字段的位置大小设定打印位置<br> //v.SetBounds(x, BandDetail.y, Grid1.Columns.Width + 1, BandDetail.Dy);<br><br> if not bNewReport and bPrintBar then //bPrintBar指是否打印条<br> v.SetBounds(x, BandDetail.y + Grid1.RowHeight + 4, Grid1.Columns.Width + 1, Grid1.RowHeight + 4)<br> else<br> v.SetBounds(x, BandDetail.y, Grid1.Columns.Width + 1, BandDetail.Dy);<br><br> TRMMemoView(v).PAlignment := GetAlignment(Grid1.Columns.Alignment);<br> if Grid1.ShowGrid then<br> v.Prop['FrameTyp'] := $F;<br> TRMMemoView(v).Font.Assign(Grid1.Columns.Font);<br> //设置数据字段<br> v.Memo.Text := Format('[%s.%s."%s"]', [Grid1.DataSource.DataSet.Owner.Name,<br> Grid1.DataSource.DataSet.Name, Grid1.Columns.FieldName]);<br> if edgoRowAutoHeight in Grid1.OptionsView then<br> v.Prop['WordWrap'] := True ;<br> v.FillColor := Grid1.Color;<br> v.Name := 'Row1' + Grid1.Columns.Name;<br> //画饼图<br> if Grid1.Columns.FieldName = sPrintChartX then<br> sChartNameX := v.Name<br> else<br> if Grid1.Columns.FieldName = sPrintChartY then<br> sChartNameY := v.Name;<br><br> if lPrintChartType >= 0 then //如果是图形<br> begin<br> v.dy := 0;<br> v.Visible := False;<br> end;<br><br> if Page1.FindObject(v.Name) <> nil then<br> Page1.FindObject(v.Name).Assign(v)<br> else<br> Page1.Objects.Add(v);<br> x := x + Grid1.Columns.Width + 1;<br> end;<br> if bNewReport and bPrintBar then<br> BandDetail.y := BandPageHeader.y; //打印成条行表<br> if bNewReport and bPrintBar then<br> BandDetail.dy := Grid1.RowHeight * 3 + 12; //打印成条行表<br>end;<br><br>procedure TfrmPrintForm.SetGridSummary(Grid1: TdxDBGrid); //表尾<br>var<br> x, y, i, j: Integer;<br> k: real;<br> IsbigNum: Boolean;<br> m: TRMMemoView;<br> mName, mS, mS1, mS2: string;<br>begin<br> if bNewReport then<br> BandPageFooter.y := BandDetail.y + BandDetail.dy + C_HEIGHT;<br> if bNewReport then<br> BandPageFooter.dy := 0;<br> if bNewReport then<br> BandReportSummary.y := BandPageFooter.y + BandPageFooter.dy + C_HEIGHT;<br> if bNewReport then<br> BandReportSummary.dy := BandReportSummary.dy + Grid1.RowHeight + 4;<br> x := C_LEFT;<br> y := BandReportSummary.y;<br><br> x := C_LEFT;<br> if Grid1.ShowSummaryFooter then<br> begin<br> for i := 0 to Grid1.ColumnCount - 1 do<br> begin<br> if not Grid1.Columns.Visible then<br> Continue;<br> if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false) then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> m.SetBounds(x, y, Grid1.Columns.Width + 1,<br> Grid1.RowHeight + 4);<br> m.PAlignment := GetAlignment(Grid1.Columns.Alignment);<br> if Grid1.ShowGrid then<br> m.Prop['FrameTyp'] := $F;<br> m.Font.Assign(Grid1.Columns.Font);<br> m.Memo.Text := Grid1.Columns.SummaryFooterText;<br> m.FillColor := Grid1.Color;<br> m.Name := 'Summary' + Grid1.Columns.Name;<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Grid1.Columns.Width + 1;<br> end;<br> end;<br>end;<br><br>procedure TfrmPrintForm.LoadDBTree(Tree1: TdxDBTreeList);<br>begin<br> if (Tree1 = nil) or (Tree1.Datasource = nil) or (Tree1.Datasource.Dataset =<br> nil) then<br> Exit;<br> if not Tree1.Datasource.Dataset.Active then<br> Exit;<br> RMDBDataSet1.DataSource := Tree1.DataSource;<br> rmReport.DataSet := RMDBDataSet1;<br> if Tree1.Tag = 5 then<br> bPrintBar := True<br> else<br> bPrintBar := False;<br> SetTreeHeader(Tree1); //表头<br> SetTreeBody(Tree1); //表体<br> SetTreeSummary(Tree1); //表尾<br>end;<br><br>procedure TfrmPrintForm.SetTreeHeader(Tree1: TdxDBTreeList);<br>var<br> x, i: Integer;<br> m: TRMMemoView;<br>begin<br> if bNewReport then<br> BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;<br> if Tree1.ShowBands then //表头1<br> begin<br> x := C_LEFT;<br> if bNewReport then<br> BandPageHeader.dy := BandPageHeader.dy + Tree1.RowHeight + 4;<br> if bNewReport and bPrintBar then<br> BandPageHeader.dy := 0; //打印成条行表<br> for i := 0 to Tree1.Bands.Count - 1 do<br> begin<br> if not Tree1.Bands.Visible then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> m.SetBounds(x, BandPageHeader.y, Tree1.Bands.Width +<br> GetBandSub(Tree1, Tree1.Bands.Index), Tree1.RowHeight + 4);<br> m.Font.Assign(Tree1.BandFont);<br> m.Memo.Text := Tree1.Bands.Caption;<br> m.PLayout := rmtlCenter;<br> m.PAlignment := GetAlignment(Tree1.Bands.Alignment);<br> m.FillColor := Tree1.Color;<br> // if Tree1.ShowGrid then m.FrameTyp := $F;<br> m.Prop['FrameTyp'] := $F;<br> m.Name := 'Grid_Band_' + IntToStr(i);<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Tree1.Bands.Width + GetBandSub(Tree1, Tree1.Bands.Index);<br> end;<br> end;<br> if Tree1.ShowHeader then //表头2<br> begin<br> x := C_LEFT;<br> if bNewReport then<br> BandPageHeader.dy := BandPageHeader.dy + Tree1.RowHeight + 4;<br> if bNewReport and bPrintBar then<br> BandPageHeader.dy := 0; //打印成条行表<br> for i := 0 to Tree1.ColumnCount - 1 do<br> begin<br> if not Tree1.Columns.Visible then<br> Continue;<br> if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false) then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> if Tree1.ShowBands then<br> m.SetBounds(x, BandPageHeader.y + Tree1.RowHeight + 4,<br> Tree1.Columns.Width + 1, Tree1.RowHeight + 4)<br> else<br> m.SetBounds(x, BandPageHeader.y, Tree1.Columns.Width + 1,<br> Tree1.RowHeight + 4);<br> m.Font.Assign(Tree1.Columns.Font);<br> m.Memo.Text := Tree1.Columns.Caption;<br> m.PLayout := rmtlCenter;<br> m.PAlignment := GetAlignment(Tree1.Columns.Alignment);<br> m.FillColor := Tree1.Color;<br> m.Prop['FrameTyp'] := $F;<br> m.Name := 'Row0' + Tree1.Columns.Name;<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Tree1.Columns.Width + 1;<br> end;<br> end;<br>end;<br><br>procedure TfrmPrintForm.SetTreeBody(Tree1: TdxDBTreeList);<br>var<br> x, i: Integer;<br> v: TRMView;<br>begin<br> //画出表体<br> if bNewReport then<br> BandDetail.y := BandPageHeader.y + BandPageHeader.dy + C_HEIGHT;<br> if bNewReport then<br> BandDetail.dy := Tree1.RowHeight + 4;<br><br> x := C_LEFT;<br> for i := 0 to Tree1.ColumnCount - 1 do<br> begin<br> if not Tree1.Columns.Visible then<br> Continue;<br> if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false) then<br> Continue;<br> v := RMCreateObject(gtMemo, '');<br><br> if not bNewReport and bPrintBar then<br> v.SetBounds(x, BandDetail.y + Tree1.RowHeight + 4, Tree1.Columns.Width + 1, Tree1.RowHeight + 4)<br> else<br> v.SetBounds(x, BandDetail.y, Tree1.Columns.Width + 1, BandDetail.Dy);<br><br> TRMMemoView(v).PAlignment := GetAlignment(Tree1.Columns.Alignment);<br> if Tree1.ShowGrid then<br> v.Prop['FrameTyp'] := $F;<br> v.Prop['FrameTyp'] := $F;<br> TRMMemoView(v).Font.Assign(Tree1.Columns.Font);<br> //设置数据字段<br> v.Memo.Text := Format('[%s.%s."%s"]', [Tree1.DataSource.DataSet.Owner.Name,<br> Tree1.DataSource.DataSet.Name, Tree1.Columns.FieldName]);<br> v.FillColor := Tree1.Color;<br> v.Name := 'Row1' + Tree1.Columns.Name;<br> //画饼图<br> if Tree1.Columns.FieldName = sPrintChartX then<br> sChartNameX := v.Name<br> else<br> if Tree1.Columns.FieldName = sPrintChartY then<br> sChartNameY := v.Name;<br><br> if lPrintChartType >= 0 then //如果是图形<br> begin<br> v.dy := 0;<br> v.Visible := False;<br> end;<br><br> if Page1.FindObject(v.Name) <> nil then<br> Page1.FindObject(v.Name).Assign(v)<br> else<br> Page1.Objects.Add(v);<br> x := x + Tree1.Columns.Width + 1;<br> end;<br> if bNewReport and bPrintBar then<br> BandDetail.y := BandPageHeader.y; //打印成条行表<br> if bNewReport and bPrintBar then<br> BandDetail.dy := Tree1.RowHeight * 3 + 12; //打印成条行表<br>end;<br><br>procedure TfrmPrintForm.SetTreeSummary(Tree1: TdxDBTreeList); //表尾<br>var<br> x, i: Integer;<br> m: TRMMemoView;<br>begin<br> if bNewReport then<br> BandPageFooter.y := BandDetail.y + BandDetail.dy + C_HEIGHT;<br> if bNewReport then<br> BandPageFooter.dy := 0;<br> if bNewReport then<br> BandReportSummary.y := BandPageFooter.y + BandPageFooter.dy + C_HEIGHT;<br> if bNewReport then<br> BandReportSummary.dy := BandReportSummary.dy + Tree1.RowHeight + 4;<br> x := C_LEFT;<br> if Tree1.ShowFooter then<br> begin<br> for i := 0 to Tree1.ColumnCount - 1 do<br> begin<br> if not Tree1.Columns.Visible then<br> Continue;<br> if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false) then<br> Continue;<br> m := TRMMemoView(RMCreateObject(gtMemo, ''));<br> m.SetBounds(x, BandReportSummary.y, Tree1.Columns.Width + 1,<br> Tree1.RowHeight + 4);<br> m.PAlignment := GetAlignment(Tree1.Columns.Alignment);<br> if Tree1.ShowGrid then<br> m.Prop['FrameTyp'] := $F;<br> m.Prop['FrameTyp'] := $F;<br> m.Font.Assign(Tree1.Columns.Font);<br> m.Memo.Text := Tree1.Columns.SummaryFooterText; // .SummaryFooterFormat;<br> m.FillColor := Tree1.Color;<br> m.Name := 'Summary' + Tree1.Columns.Name;<br> if Page1.FindObject(m.Name) <> nil then<br> Page1.FindObject(m.Name).Assign(m)<br> else<br> Page1.Objects.Add(m);<br> x := x + Tree1.Columns.Width + 1;<br> end;<br> end;<br>end;<br><br>function TfrmPrintForm.GetPoint(Control: TControl): TPoint;<br>var<br> Point: TPoint;<br>begin<br> Point.x := 0;<br> Point.y := 0;<br> Point := Control.ClientToScreen(point);<br> Point := frmForm1.ScreenToClient(Point);<br> Result := Point;<br>end;<br><br>function TfrmPrintForm.GetAlignment(Align: TAlignment): TRMAlignment;<br>begin<br> case Align of<br> taLeftJustify: Result := rmtaLeftJustify;<br> taRightJustify: Result := rmtaRightJustify;<br> taCenter: Result := rmtaCenterJustify;<br> else<br> Result := rmtaLeftJustify;<br> end;<br>end;<br><br>function TfrmPrintForm.ViewAssign(m1: TRMMemoView; Control: TControl): Boolean;<br>begin<br> Result := true;<br><br> if Control is TSeSkinLabel then<br> begin //标准控件<br> m1.Font.Assign(TSeSkinLabel(Control).Font);<br> m1.Memo.Text := TSeSkinLabel(Control).Caption;<br> end<br> else<br> if Control is TCustomEdit then<br> begin<br> m1.Font.Assign(TEdit(Control).Font);<br> m1.Memo.Text := TEdit(Control).Text;<br> end<br> else<br> if Control is TCustomMemo then<br> begin<br> m1.Font.Assign(TMemo(Control).Font);<br> m1.Memo.Assign(TMemo(Control).Lines);<br> end<br> else<br> if Control is TCustomdxEdit then<br> begin //Express No DB<br> m1.Font.Assign(TdxEdit(Control).Font);<br> m1.Memo.Text := TdxEdit(Control).Text;<br> end<br> else<br> if Control is TCustomdxDateEdit then<br> begin<br> m1.Font.Assign(TdxDateEdit(Control).Font);<br> m1.Memo.Text := TdxDateEdit(Control).Text;<br> end<br> else<br> if Control is TCustomdxPickEdit then<br> begin<br> m1.Font.Assign(TdxPickEdit(Control).Font);<br> m1.Memo.Text := TdxPickEdit(Control).Text;<br> end<br> else<br> if Control is TdxButtonEdit then<br> begin<br> m1.Font.Assign(TdxButtonEdit(Control).Font);<br> m1.Memo.Text := TCustomdxButtonEdit(Control).Text;<br> end<br> else<br> if Control is TCustomdxDBEdit then<br> begin //Express is DB<br> m1.Font.Assign(TdxDBEdit(Control).Font);<br> m1.Memo.Text := TdxDBEdit(Control).Text;<br> end<br> else<br> if Control is TCustomdxDBDateEdit then<br> begin<br> m1.Font.Assign(TdxDBDateEdit(Control).Font);<br> m1.Memo.Text := TdxDBDateEdit(Control).Text;<br> end<br> else<br> if Control is TCustomdxDBPickEdit then<br> begin<br> m1.Font.Assign(TdxDBPickEdit(Control).Font);<br> m1.Memo.Text := TdxDBPickEdit(Control).Text;<br> end<br> else<br> if Control is TdxDBButtonEdit then<br> begin<br> m1.Font.Assign(TdxDBButtonEdit(Control).Font);<br> m1.Memo.Text := TCustomdxDBButtonEdit(Control).Text;<br> end<br> else<br> if Control is TdxInplaceTextEdit then<br> begin<br> m1.Font.Assign(frmForm1.Font);<br> m1.Memo.Text := TdxInplaceTextEdit(Control).Text;<br> end<br> else<br> Result := false;<br>end;<br><br>function TfrmPrintForm.ShapeViewAssign(s1: TRMShapeView; Control: TControl):<br> Boolean;<br>begin<br> Result := True;<br> if Control is TShape then<br> begin<br> {$IFNDEF NoRmComPass}<br> case TShape(Control).Shape of<br> stRectangle: s1.ShapeType := rmskRectangle;<br> stSquare: s1.ShapeType := rmskRectangle;<br> stRoundRect: s1.ShapeType := rmskRectangle;<br> stRoundSquare: s1.ShapeType := rmskRectangle;<br> stEllipse: s1.ShapeType := rmskRectangle;<br> stCircle: s1.ShapeType := rmskRectangle;<br> end;<br> {$ELSE}<br><br> {$ENDIF}<br> s1.FillColor := TShape(Control).Brush.Color;<br> s1.dx := TShape(Control).Pen.Width;<br> s1.FillColor := TShape(Control).Pen.Color;<br> s1.PenMode := TShape(Control).Pen.Mode;<br> end<br> else<br> Result := false;<br>end;<br><br>function TfrmPrintForm.PicViewAssign(p1: TRMPictureView; Control: TControl):<br> Boolean;<br>begin<br> Result := True;<br> if Control is TImage then<br> begin<br> if TImage(Control).Picture.Graphic <> nil then<br> p1.Picture.Assign(TImage(Control).Picture);<br> p1.Flags := (p1.Flags and not flPictCenter) + Word(TImage(Control).Center) *<br> flPictCenter;<br> p1.Flags := (p1.Flags and not flStretched) + Word(TImage(Control).Stretch) *<br> flStretched;<br> p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;<br> end<br> else<br> if Control is TdxGraphicEdit then<br> begin<br> if TdxGraphicEdit(Control).Picture.Graphic <> nil then<br> p1.Picture.Assign(TdxGraphicEdit(Control).Picture);<br> p1.Flags := (p1.Flags and not flPictCenter) +<br> Word(TdxGraphicEdit(Control).Center) * flPictCenter;<br> p1.Flags := (p1.Flags and not flStretched) +<br> Word(TdxGraphicEdit(Control).Stretch) * flStretched;<br> p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;<br> end<br> else<br> if Control is TdxDBGraphicEdit then<br> begin<br> if TdxDBGraphicEdit(Control).Picture.Graphic <> nil then<br> p1.Picture.Assign(TdxDBGraphicEdit(Control).Picture);<br> p1.Flags := (p1.Flags and not flPictCenter) +<br> Word(TdxDBGraphicEdit(Control).Center) * flPictCenter;<br> p1.Flags := (p1.Flags and not flStretched) +<br> Word(TdxDBGraphicEdit(Control).Stretch) * flStretched;<br> p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;<br> end<br> else<br> Result := false;<br>end;<br><br>end.<br>=================================================================================<br>调用该dll的文件:<br><br>program Project2;<br><br>uses<br> Forms,<br> Unit2 in 'Unit2.pas' {Form1};<br><br>{$R *.res}<br><br>begin<br> Application.Initialize;<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>end.<br><br>------------------------------------------------------------------------------<br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, DB, ADODB, dxExEdtr, dxCntner, dxTL, dxDBCtrl,<br> dxDBGrid, dxDBTLCl, dxGrClms;<br><br>const<br> SHOW_REPORT = 1;<br> PRINT_REPORT = 2;<br> DESIGN_REPORT = 3;<br> INITI_REPORT = 4;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> ADODataSet1: TADODataSet;<br> ADOConnection1: TADOConnection;<br> dxDBGrid1: TdxDBGrid;<br> DataSource1: TDataSource;<br> dxDBGrid1ID: TdxDBGridMaskColumn;<br> dxDBGrid1Date: TdxDBGridDateColumn;<br> dxDBGrid1PCName: TdxDBGridColumn;<br> dxDBGrid1Employee: TdxDBGridColumn;<br> dxDBGrid1Operate: TdxDBGridColumn;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br><br> end;<br><br>var<br> Form1: TForm1;<br><br> function WinPrint(Form1: TForm; lTitle1, lMode1: Integer; sFile1, sChart1:<br> string): Boolean; external 'project1.DLL';<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> winprint(self, 1, DESIGN_REPORT, '', '')<br>end;<br><br>end.