📄 rm_formreport.pas
字号:
finally
tmpForm.Free;
end;
end;
procedure TRMCustomGridReport.ChangePageLayout(aPageSetting: TRMPageSetting);
begin
PageLayout.Title := aPageSetting.Title;
PageLayout.PrinterName := aPageSetting.PrinterName;
PageLayout.DoublePass := aPageSetting.DoublePass;
PageLayout.pgOr := aPageSetting.PageOr;
PageLayout.Columns := aPageSetting.ColCount;
PageLayout.ColumnSpace := Round(RMConvertToPixels(aPageSetting.ColGap * 10, rmsuMM));
PageLayout.PrintBackColor := aPageSetting.PrintBackColor;
PageLayout.LeftMargin := Round(RMConvertToPixels(aPageSetting.MarginLeft * 10, rmsuMM));
PageLayout.TopMargin := Round(RMConvertToPixels(aPageSetting.MarginTop * 10, rmsuMM));
PageLayout.RightMargin := Round(RMConvertToPixels(aPageSetting.MarginRight * 10, rmsuMM));
PageLayout.BottomMargin := Round(RMConvertToPixels(aPageSetting.MarginBottom * 10, rmsuMM));
PageLayout.Width := aPageSetting.PageWidth;
PageLayout.Height := aPageSetting.PageHeight;
PageLayout.pgBin := aPageSetting.PageBin;
PageLayout.pgSize := aPageSetting.PageSize;
end;
function TRMCustomGridReport.CreateReportFromGrid: Boolean;
begin
Result := FALSE;
end;
procedure TRMCustomGridReport.SetGroups(Value: TRMGroupItems);
begin
FGroups.Assign(Value);
end;
function TRMCustomGridReport.GetReport: TRMReport;
begin
if FReport = nil then
begin
FReport := TRMReport.Create(RMDialogForm);
THackReport(FReport).FDefaultDatasetOwner := Owner;
end;
Result := FReport;
end;
function TRMCustomGridReport.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 TRMCustomGridReport.SetPageHeader(Value: TRMPageHeaderFooter);
begin
FPageHeader.Assign(Value);
end;
procedure TRMCustomGridReport.SetPageFooter(Value: TRMPageHeaderFooter);
begin
FPageFooter.Assign(Value);
end;
procedure TRMCustomGridReport.SetColumnFooter(Value: TRMPageHeaderFooter);
begin
FColumnFooter.Assign(Value);
end;
procedure TRMCustomGridReport.SetMasterDataBandOptions(Value: TRMMasterDataBandOptions);
begin
FMasterDataBandOptions.Assign(Value);
end;
procedure TRMCustomGridReport.SetGridNumOptions(Value: TRMGridNumOptions);
begin
FGridNumOptions.Assign(Value);
end;
procedure TRMCustomGridReport.SetScaleMode(Value: TRMScaleOptions);
begin
FScaleMode.Assign(Value);
end;
procedure TRMCustomGridReport.SetPageLayout(Value: TRMPageLayout);
begin
FPageLayout.Assign(Value);
end;
{procedure TRMCustomGridReport.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;
FDataSet := nil;
FDataSource := 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;
end;
end;
type
THackStretcheable = class(TRMStretcheable)
end;
function TRMFormReport.CreateReportFromGrid: Boolean;
var
i, j: Integer;
liPage: TRMPage;
liBandPageHeader: TRMBandView;
liBandPageDetail: TRMBandView;
liBandColumnFooter: TRMBandView;
liBandPageFooter: TRMBandView;
liBandReportSummary: TRMBandView;
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 PrintObject(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
FOnAfterCreateObject(Sender, liView);
if not tmp.AutoFree then
FReportObjects.Add(tmp);
finally
if tmp.AutoFree then
tmp.Free;
end;
end;
liFound := liFound or liOwnerDraw;
if (not liFound) and (Sender is TWinControl) and (TWinControl(Sender).ControlCount > 0) then
begin
liList := TList.Create;
try
for i := 0 to TWinControl(Sender).ControlCount - 1 do
liList.Add(TWinControl(Sender).Controls[I]);
liList.Sort(ListSortCompare); //按上到下、左到右排序
for i := 0 to liList.Count - 1 do
PrintObject(TControl(liList[i]), aOffsetX + TWinControl(Sender).Left, aOffsetY + TWinControl(Sender).Top);
finally
liList.Free;
end;
end;
OffsX := OldOffsX; OffsY := OldOffsY;
end;
procedure MakeGroups;
var
i, j, liNextY: Integer;
liBandView: TRMBandView;
liDataSet: TDataSet;
begin
liDataSet := nil;
if ReportDataSet.DataSet <> nil then
liDataSet := ReportDataSet.DataSet
else if (ReportDataSet.DataSource <> nil) and (ReportDataSet.DataSource.DataSet <> nil) then
liDataSet := ReportDataSet.DataSource.DataSet;
if liDataSet = nil then Exit;
for i := 0 to Report.Pages.Count - 1 do
begin
liPage := Report.Pages[i];
for j := 0 to FGroups.Count - 1 do
begin
if (Length(FGroups[j].GroupFieldName) > 0) then
begin
liBandView := TRMBandView(RMCreateObject(gtBand, ''));
liBandView.CreateUniqueName;
liBandView.BandType := btGroupHeader;
liBandView.PNewPageAfter := FGroups[j].FormNewPage;
if liDataSet.FindField(FGroups[j].GroupFieldName) <> nil then
liBandView.GroupCondition := Format('[%s.%s."%s"]', [liDataSet.Owner.Name, liDataSet.Name, FGroups[j].GroupFieldName])
else
liBandView.GroupCondition := FGroups[j].GroupFieldName;
liBandView.SetBounds(0, NextY + 1, 0, 0);
Inc(NextY, 1);
liPage.Objects.Add(liBandView);
end;
end;
liNextY := NextY;
for j := FGroups.Count - 1 downto 0 do
begin
if Length(FGroups[j].GroupFieldName) > 0 then
begin
liBandView := TRMBandView(RMCreateObject(gtBand, ''));
liBandView.CreateUniqueName;
liBandView.BandType := btGroupFooter;
liBandView.SetBounds(0, liNextY + 1, 0, 0);
Inc(liNextY, 1);
liPage.Objects.Add(liBandView);
liGroupFooterBands.Add(liBandView);
end;
end;
end;
end;
procedure MakeGroupFooter;
var
i, j, k, SaveNextY: Integer;
liGroupFooter: TRMBandView;
liPage: TRMPage;
begin
if liGroupFooterBands.Count > 0 then
begin
k := 0;
SaveNextY := NextY;
for i := 0 to Report.Pages.Count - 1 do
begin
NextY := SaveNextY;
liPage := Report.Pages[i];
liGroupFooter := TRMBandView(liGroupFooterBands[k]);
liGroupFooter.y := NextY;
for j := 0 to FGroupFooterViews.Count - 1 do
begin
if liPage.FindObject(TRMView(FGroupFooterViews[j]).Name) <> nil then
begin
Inc(TRMView(FGroupFooterViews[j]).y, NextY);
CalcRect(TRMView(FGroupFooterViews[j]), TRMBandView(liGroupFooterBands[0]), StrToInt(FormWidth[i]));
TRMBandView(liGroupFooterBands[k]).dy := Max(TRMBandView(liGroupFooterBands[k]).dy, TRMView(FGroupFooterViews[j]).y + TRMView(FGroupFooterViews[j]).dy - TRMBandView(liGroupFooterBands[k]).y);
end;
end;
Inc(k);
NextY := liGroupFooter.y + liGroupFooter.dy + 1;
for j := k to liGroupFooterBands.Count - 1 do
begin
if liPage.FindObject(TRMBandView(liGroupFooterBands[j]).Name) <> nil then
begin
TRMBandView(liGroupFooterBands[j]).y := NextY;
NextY := NextY + TRMBandView(liGroupFooterBands[j]).dy + 1;
Inc(k);
end;
end;
end;
end;
end;
procedure MakePageHeader;
var
i, j: Integer;
liPage: TRMPage;
{$IFDEF INFOPOWER}
t: TRMwwRichView;
{$ELSE}
{$IFDEF RX}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -