📄 rm_formreport.pas
字号:
begin
t.spLeft := t.spLeft + (PageWidth - Round(aFormWidth * liScale)) div 2;
end;
if FScaleMode.CenterOnPageV and (not HaveDetailBand) then //垂直居中
begin
t.spTop := t.spTop + (PageHeight - Round(FormHeight * liScale)) div 2;
end;
end;
procedure TRMCustomFormReport.AddPage;
var
liPage: TRMReportPage;
begin
liPage := FReport.Pages.AddReportPage;
with PageLayout do
begin
liPage.PageMargins := Rect(LeftMargin, TopMargin, RightMargin, BottomMargin);
liPage.ColumnCount := ColumnCount;
liPage.spColumnGap := ColumnGap;
liPage.ChangePaper(PageSize, Width, Height, PageBin, PageOrientation);
end;
end;
procedure TRMCustomFormReport._InternalShowReport(aFlag: Integer);
begin
ClearRMDataSets;
Report.ModalPreview := True;
Report.OnBeforePrintBand := nil;
MainDataSet := nil;
FReport.ModalPreview := TRUE;
try
FReport.ReportInfo.Title := PageLayout.Title;
FReport.InitialZoom := FReportSettings.FInitialZoom;
FReport.PreviewButtons := FReportSettings.FPreviewButtons;
FReport.Preview := FReportSettings.FPreview;
FReport.ShowProgress := FReportSettings.FShowProgress;
FReport.ModifyPrepared := FReportSettings.FModifyPrepared;
FReport.ShowPrintDialog := FReportSettings.FShowPrintDialog;
FReport.ReportInfo.Title := FReportSettings.FReportTitle;
if rmgoRebuildAfterPageChanged in ReportOptions then
THackReport(FReport).OnAfterPreviewPageSetup := OnAfterPreviewPageSetup
else
THackReport(FReport).OnAfterPreviewPageSetup := nil;
FReport.Pages.Clear;
with PageLayout do
begin
FReport.DoublePass := DoublePass;
THackReport(FReport).PrinterName := PrinterName;
end;
AddPage;
if CreateReportFromGrid then
begin
try
if (rmgoDisableControls in ReportOptions) and (MainDataSet <> nil) and (MainDataSet.DataSet <> nil) then
MainDataSet.DataSet.DisableControls;
case aFlag of
1: FReport.ShowReport;
2: FReport.PrintReport;
3: FReport.DesignReport;
end;
finally
if (rmgoDisableControls in ReportOptions) and (MainDataSet <> nil) and (MainDataSet.DataSet <> nil) then
MainDataSet.DataSet.EnableControls;
end;
end;
finally
end;
end;
procedure TRMCustomFormReport.ShowReport;
begin
_InternalShowReport(1);
end;
procedure TRMCustomFormReport.PrintReport;
begin
_InternalShowReport(2);
end;
procedure TRMCustomFormReport.DesignReport;
begin
_InternalShowReport(3);
end;
procedure TRMCustomFormReport.BuildReport;
begin
_InternalShowReport(0);
end;
procedure TRMCustomFormReport.OnAfterPreviewPageSetup(Sender: TObject);
begin
ChangePageLayout(TRMPageSetting(Sender));
BuildReport;
end;
function TRMCustomFormReport.PageSetup: Boolean;
var
tmpForm: TRMPageSetupForm;
begin
Result := False;
tmpForm := TRMPageSetupForm.Create(Application);
try
tmpForm.PageSetting.Title := PageLayout.Title;
tmpForm.PageSetting.DoublePass := PageLayout.DoublePass;
tmpForm.PageSetting.PageOr := PageLayout.PageOrientation;
tmpForm.PageSetting.MarginLeft := RMRound(RMToMMThousandths(PageLayout.LeftMargin, rmutScreenPixels) / 1000, 1);
tmpForm.PageSetting.MarginTop := RMRound(RMToMMThousandths(PageLayout.TopMargin, rmutScreenPixels) / 1000, 1);
tmpForm.PageSetting.MarginRight := RMRound(RMToMMThousandths(PageLayout.RightMargin, rmutScreenPixels) / 1000, 1);
tmpForm.PageSetting.MarginBottom := RMRound(RMToMMThousandths(PageLayout.BottomMargin, rmutScreenPixels) / 1000, 1);
tmpForm.PageSetting.PageWidth := PageLayout.Width;
tmpForm.PageSetting.PageHeight := PageLayout.Height;
tmpForm.PageSetting.PageSize := PageLayout.PageSize;
tmpForm.PageSetting.PageBin := PageLayout.PageBin;
tmpForm.PageSetting.PrinterName := PageLayout.PrinterName;
tmpForm.PageSetting.ColorPrint := PageLayout.ColorPrint;
tmpForm.PageSetting.ColCount := PageLayout.ColumnCount;
tmpForm.PageSetting.ColGap := RMFromScreenPixels(PageLayout.ColumnGap, rmutMillimeters);
if tmpForm.ShowModal = mrOk then
begin
ChangePageLayout(tmpForm.PageSetting);
Result := True;
end;
finally
tmpForm.Free;
end;
end;
procedure TRMCustomFormReport.ChangePageLayout(aPageSetting: TRMPageSetting);
begin
PageLayout.Title := aPageSetting.Title;
PageLayout.PrinterName := aPageSetting.PrinterName;
PageLayout.DoublePass := aPageSetting.DoublePass;
PageLayout.PageOrientation := aPageSetting.PageOr;
PageLayout.ColorPrint := aPageSetting.ColorPrint;
PageLayout.LeftMargin := Round(RMToScreenPixels(aPageSetting.MarginLeft * 1000, rmutMMThousandths));
PageLayout.TopMargin := Round(RMToScreenPixels(aPageSetting.MarginTop * 1000, rmutMMThousandths));
PageLayout.RightMargin := Round(RMToScreenPixels(aPageSetting.MarginRight * 1000, rmutMMThousandths));
PageLayout.BottomMargin := Round(RMToScreenPixels(aPageSetting.MarginBottom * 1000, rmutMMThousandths));
PageLayout.Width := aPageSetting.PageWidth;
PageLayout.Height := aPageSetting.PageHeight;
PageLayout.PageBin := aPageSetting.PageBin;
PageLayout.PageSize := aPageSetting.PageSize;
PageLayout.ColumnCount := aPageSetting.ColCount;
PageLayout.ColumnGap := RMToScreenPixels(aPageSetting.ColGap, rmutMillimeters);
end;
function TRMCustomFormReport.CreateReportFromGrid: Boolean;
begin
Result := False;
end;
procedure TRMCustomFormReport.SetGroups(Value: TRMGroupItems);
begin
FGroups.Assign(Value);
end;
function TRMCustomFormReport.GetReport: TRMReport;
begin
if FReport = nil then
begin
FReport := TRMReport.Create(RMDialogForm);
end;
Result := FReport;
end;
{function TRMCustomFormReport.GetReportDataSet: TRMDBDataSet;
var
i: Integer;
str: string;
begin
if FReportDataSet = nil then
begin
FReportDataSet := TRMDBDataSet.Create(RMDialogForm);
i := 1;
while True do
begin
str := 'RMGridDataSet' + IntToStr(i);
if RMDialogForm.FindComponent(str) = nil then
begin
FReportDataSet.Name := str;
Break;
end;
Inc(i);
end;
end;
Result := FReportDataSet;
end;
}
procedure TRMCustomFormReport.SetPageHeader(Value: TRMPageHeaderFooter);
begin
FPageHeader.Assign(Value);
end;
procedure TRMCustomFormReport.SetPageFooter(Value: TRMPageHeaderFooter);
begin
FPageFooter.Assign(Value);
end;
procedure TRMCustomFormReport.SetColumnFooter(Value: TRMPageHeaderFooter);
begin
FColumnFooter.Assign(Value);
end;
procedure TRMCustomFormReport.SetMasterDataBandOptions(Value: TRMMasterDataBandOptions);
begin
FMasterDataBandOptions.Assign(Value);
end;
procedure TRMCustomFormReport.SetGridNumOptions(Value: TRMGridNumOptions);
begin
FGridNumOptions.Assign(Value);
end;
procedure TRMCustomFormReport.SetScaleMode(Value: TRMScaleOptions);
begin
FScaleMode.Assign(Value);
end;
procedure TRMCustomFormReport.SetPageLayout(Value: TRMPageLayout);
begin
FPageLayout.Assign(Value);
end;
procedure TRMCustomFormReport.SetGridFontOptions(Value: TRMGridFontOptions);
begin
FGridFontOptions.Assign(Value);
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMFormReportObject}
constructor TRMFormReportObject.Create;
begin
inherited Create;
AutoFree := True;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMAddinFormReportObjectInfo}
constructor TRMAddInFormReportObjectInfo.Create(AClassRef: TClass; AObjectClass: TClass);
begin
inherited Create;
FClassRef := AClassRef;
FObjectClass := AObjectClass;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMFormReport}
constructor TRMFormReport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FReportObjects := TList.Create;
FPrintControl := nil;
FDetailPrintControl := nil;
FDataSet := nil;
FDetailDataSet := nil;
CanSetDataSet := True;
FGridFixedCols := 0;
end;
destructor TRMFormReport.Destroy;
begin
Clear;
FReportObjects.Free;
inherited Destroy;
end;
procedure TRMFormReport.Clear;
begin
while FReportObjects.Count > 0 do
begin
TRMFormReportObject(FReportObjects[0]).Free;
FReportObjects.Delete(0);
end;
end;
procedure TRMFormReport.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = FPrintControl then
PrintControl := nil
else if AComponent = FDetailPrintControl then
FDetailPrintControl := nil;
end;
end;
type
THackStretcheable = class(TRMStretcheableView)
end;
function TRMFormReport.CreateReportFromGrid: Boolean;
var
i, j: Integer;
liPage: TRMReportPage;
liBandPageHeader: TRMBandPageHeader;
liBandColumnHeader: TRMBandColumnHeader;
liBandMasterData: TRMBandMasterData;
liBandColumnFooter: TRMBandColumnFooter;
liBandPageFooter: TRMBandPageFooter;
liBandReportSummary: TRMBandReportSummary;
liDetailBandList: TStringList;
liGroupFooterBands: TList;
Nexty: Integer;
procedure _GetFormRect;
var
i: Integer;
liLeft, liTop: Integer;
begin
if PrintControl is TScrollingWinControl then
begin
with TScrollingWinControl(PrintControl) do
begin
HorzScrollBar.Position := 0;
VertScrollBar.Position := 0;
end;
end;
if PrintControl.ControlCount > 0 then
begin
FormHeight := 0;
liLeft := 99999;
liTop := 99999;
for i := 0 to PrintControl.ControlCount - 1 do
begin
liLeft := Min(liLeft, PrintControl.Controls[i].Left);
liTop := Min(liTop, PrintControl.Controls[i].Top);
FormWidth[0] := IntToStr(Max(StrToInt(FormWidth[0]), PrintControl.Controls[i].Left + PrintControl.Controls[i].Width));
FormHeight := Max(FormHeight, PrintControl.Controls[i].Top + PrintControl.Controls[i].Height);
end;
FormWidth[0] := IntToStr(StrToInt(FormWidth[0]) - liLeft);
FormHeight := FormHeight - liTop;
end
else
begin
FormWidth[0] := IntToStr(PrintControl.ClientWidth);
FormHeight := PrintControl.ClientHeight;
end;
end;
procedure _PrintOneObject(Sender: TControl; aOffsetX, aOffsetY: Integer);
var
i: Integer;
OldOffsX, OldOffsY: Integer;
liList: TList;
tmp: TRMFormReportObject;
liPrintObjectClass: TClass;
liOwnerDraw: Boolean;
liFound: Boolean;
liView: TRMView;
begin
OldOffsX := OffsX;
OldOffsY := OffsY;
OffsX := aOffsetX;
OffsY := aOffsetY;
if Sender is TScrollingWinControl then
begin
with TScrollingWinControl(Sender) do
begin
HorzScrollBar.Position := 0;
VertScrollBar.Position := 0;
end;
end;
liPrintObjectClass := nil;
liOwnerDraw := False;
liFound := False;
if Assigned(FOnPrintObject) then
FOnPrintObject(Self, liPage, Sender, liPrintObjectClass, liOwnerDraw);
if (not liOwnerDraw) and (liPrintObjectClass = nil) then
begin
for i := FFormReportList.Count - 1 downto 0 do
begin
if Sender is TRMAddInFormReportObjectInfo(FFormReportList[i]).ClassRef then
begin
liFound := True;
liPrintObjectClass := TRMAddInFormReportObjectInfo(FFormReportList[i]).ObjectClass;
Break;
end;
end;
end;
if (not liOwnerDraw) and (liPrintObjectClass <> nil) then
begin
tmp := TRMFormReportObject(liPrintObjectClass.NewInstance);
tmp.Create;
try
liView := nil;
tmp.OnGenerate_Object(Self, liPage, Sender, liView);
if (liView <> nil) and Assigned(FOnAfterCreateObject) then
FOnAfterCreateObjec
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -