📄 printform.pas
字号:
BandReportTitle.y := C_HEIGHT;
BandReportTitle.dy := 40;
lTitleY := BandReportTitle.dy + C_HEIGHT;
end
end;
procedure TfrmPrintForm.LoadControl(Control: TControl);
var
m: TRMMemoView;
p: TRMPictureView;
s: TRMShapeView;
begin
if Control.Parent.Visible = False then
exit;
if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is
TdxDBGraphicEdit) then
begin
p := TRMPictureView(RMCreateObject(gtPicture, ''));
p.gapx := 0;
p.gapy := 0;
p.dx := 0;
p.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not PicViewAssign(p, Control) then
exit;
p.Name := Control.Name;
Page1.Objects.Add(p);
if (BandReportTitle.dy < (p.y + p.dy)) and (p.y < (lGridY + lTitleY)) then
BandReportTitle.dy := p.y + p.dy;
if p.y > (lGridY + lTitleY) then
begin
p.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (p.y - BandReportSummary.y + p.dy)) then
BandReportSummary.dy := (p.y - BandReportSummary.y + p.dy);
end;
end
else
if (Control is TShape) then
begin
s := TRMShapeView(RMCreateObject(gtAddin, 'TRMShapeView'));
s.gapx := 0;
s.gapy := 0;
s.dx := 0;
s.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not ShapeViewAssign(s, Control) then
exit;
s.Name := Control.Name;
Page1.Objects.Add(s);
if (BandReportTitle.dy < (s.y + s.dy)) and (s.y < (lGridY + lTitleY)) then
BandReportTitle.dy := s.y + s.dy;
if s.y > (lGridY + lTitleY) then
begin
s.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (s.y - BandReportSummary.y + s.dy)) then
BandReportSummary.dy := (s.y - BandReportSummary.y + s.dy);
end;
end
else
begin
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.gapx := 0;
m.gapy := 0;
m.dx := 0;
m.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not ViewAssign(m, Control) then
exit;
m.Name := Control.Name;
Page1.Objects.Add(m);
if (BandReportTitle.dy < (m.y + m.dy)) and (m.y < (lGridY + lTitleY)) then
BandReportTitle.dy := m.y + m.dy;
if m.y > (lGridY + lTitleY) then
begin
m.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (m.y - BandReportSummary.y + m.dy)) then
BandReportSummary.dy := (m.y - BandReportSummary.y + m.dy);
end;
end;
end;
procedure TfrmPrintForm.LoadTopControl(Control: TControl); //读入最上面Control
begin
BandReportSummary.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT * 4;
if GetPoint(Control).y <= lGridY then
LoadControl(Control);
end;
procedure TfrmPrintForm.LoadBottomControl(Control: TControl); //读入最下面Control
begin
if GetPoint(Control).y >= lGridY then
LoadControl(Control);
end;
procedure TfrmPrintForm.LoadOldControl(Control: TControl);
var
v: TRMView;
begin
v := Page1.FindObject(Control.Name);
if v = nil then
exit;
if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is
TdxDBGraphicEdit) then
begin
if not PicViewAssign(TRMPictureView(v), Control) then
exit;
end
else
if (Control is TShape) then
begin
if not ShapeViewAssign(TRMShapeView(Page1.FindObject(Control.Name)), Control) then
exit;
end
else
begin
if not ViewAssign(TRMMemoView(Page1.FindObject(Control.Name)), Control) then
exit;
end;
end;
function TfrmPrintForm.GetBandSub(Grid1: TCustomdxDBTreeListControl; Index:
Integer): Integer;
var
i, j: Integer;
begin
j := 0;
for i := 0 to Grid1.ColumnCount - 1 do
if Grid1.Columns[i].Visible and (Grid1.Columns[i].BandIndex = Index) then
inc(j);
Result := j;
end;
procedure TfrmPrintForm.LoadDBGrid(Grid1: TdxDBGrid);
begin
if (Grid1 = nil) or (Grid1.Datasource = nil) or (Grid1.Datasource.Dataset =
nil) then
Exit;
if not Grid1.Datasource.Dataset.Active then
Exit;
RMDBDataSet1.DataSource := Grid1.DataSource;
rmReport.DataSet := RMDBDataSet1;
if Grid1.Tag = 5 then
bPrintBar := True
else
bPrintBar := False;
SetGridHeader(Grid1); //表头
SetGridBody(Grid1); //表体
SetGridSummary(Grid1); //表尾
end;
procedure TfrmPrintForm.SetGridHeader(Grid1: TdxDBGrid);
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;
if Grid1.ShowBands then //表头1
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0; //打印成条行表
for i := 0 to Grid1.Bands.Count - 1 do
begin
if not Grid1.Bands[i].Visible then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandPageHeader.y, Grid1.Bands[i].Width +
GetBandSub(Grid1, Grid1.Bands[i].Index), Grid1.RowHeight + 4);
m.Font.Assign(Grid1.BandFont);
m.Memo.Text := Grid1.Bands[i].Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Grid1.Bands[i].Alignment);
m.FillColor := Grid1.Color;
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Name := 'Grid_Band_' + IntToStr(i);
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Bands[i].Width + GetBandSub(Grid1, Grid1.Bands[i].Index);
end;
end;
if Grid1.ShowHeader then //表头2
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0; //打印成条行表
for i := 0 to Grid1.ColumnCount - 1 do
begin
if not Grid1.Columns[i].Visible then
Continue;
if (Grid1.Columns[i].Field = nil) and (Grid1.Columns[i].Visible = false) then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
if Grid1.ShowBands then
m.SetBounds(x, BandPageHeader.y + Grid1.RowHeight + 4,
Grid1.Columns[i].Width + 1, Grid1.RowHeight + 4)
else
m.SetBounds(x, BandPageHeader.y, Grid1.Columns[i].Width + 1,
Grid1.RowHeight + 4);
m.Font.Assign(Grid1.Columns[i].Font);
m.Memo.Text := Grid1.Columns[i].Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Grid1.Columns[i].Alignment);
m.FillColor := Grid1.Color;
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Name := 'Row0' + Grid1.Columns[i].Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Columns[i].Width + 1;
end;
end;
end;
procedure TfrmPrintForm.SetGridBody(Grid1: TdxDBGrid);
var
x, i: Integer;
v: TRMView;
begin
//画出表体
if bNewReport then
BandDetail.y := BandPageHeader.y + BandPageHeader.dy + C_HEIGHT;
if bNewReport then
BandDetail.dy := Grid1.RowHeight + 4;
x := C_LEFT;
for i := 0 to Grid1.ColumnCount - 1 do
begin
if not Grid1.Columns[i].Visible then
Continue;
if (Grid1.Columns[i].Field = nil) and (Grid1.Columns[i].Visible = false) then Continue;
v := RMCreateObject(gtMemo, '');
v.SetBounds(x, BandDetail.y, Grid1.Columns[i].Width + 1, BandDetail.Dy);
if not bNewReport and bPrintBar then
v.SetBounds(x, BandDetail.y + Grid1.RowHeight + 4, Grid1.Columns[i].Width + 1, Grid1.RowHeight + 4)
else
v.SetBounds(x, BandDetail.y, Grid1.Columns[i].Width + 1, BandDetail.Dy);
TRMMemoView(v).PAlignment := GetAlignment(Grid1.Columns[i].Alignment);
if Grid1.ShowGrid then
v.Prop['FrameTyp'] := $F;
TRMMemoView(v).Font.Assign(Grid1.Columns[i].Font);
//设置数据字段
v.Memo.Text := Format('[%s.%s."%s"]', [Grid1.DataSource.DataSet.Owner.Name,
Grid1.DataSource.DataSet.Name, Grid1.Columns[i].FieldName]);
v.FillColor := Grid1.Color;
v.Name := 'Row1' + Grid1.Columns[i].Name;
//画饼图
if Grid1.Columns[i].FieldName = sPrintChartX then
sChartNameX := v.Name
else
if Grid1.Columns[i].FieldName = sPrintChartY then
sChartNameY := v.Name;
if lPrintChartType >= 0 then //如果是图形
begin
v.dy := 0;
v.Visible := False;
end;
if Page1.FindObject(v.Name) <> nil then
Page1.FindObject(v.Name).Assign(v)
else
Page1.Objects.Add(v);
x := x + Grid1.Columns[i].Width + 1;
end;
if bNewReport and bPrintBar then
BandDetail.y := BandPageHeader.y; //打印成条行表
if bNewReport and bPrintBar then
BandDetail.dy := Grid1.RowHeight * 3 + 12; //打印成条行表
end;
procedure TfrmPrintForm.SetGridSummary(Grid1: TdxDBGrid); //表尾
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageFooter.y := BandDetail.y + BandDetail.dy + C_HEIGHT;
if bNewReport then
BandPageFooter.dy := 0;
if bNewReport then
BandReportSummary.y := BandPageFooter.y + BandPageFooter.dy + C_HEIGHT;
if bNewReport then
BandReportSummary.dy := BandReportSummary.dy + Grid1.RowHeight + 4;
x := C_LEFT;
if Grid1.ShowSummaryFooter then
begin
for i := 0 to Grid1.ColumnCount - 1 do
begin
if not Grid1.Columns[i].Visible then
Continue;
if (Grid1.Columns[i].Field = nil) and (Grid1.Columns[i].Visible = false) then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandReportSummary.y, Grid1.Columns[i].Width + 1,
Grid1.RowHeight + 4);
m.PAlignment := GetAlignment(Grid1.Columns[i].Alignment);
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Font.Assign(Grid1.Columns[i].Font);
m.Memo.Text := Grid1.Columns[i].SummaryFooterText;
m.FillColor := Grid1.Color;
m.Name := 'Summary' + Grid1.Columns[i].Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Columns[i].Width + 1;
end;
end;
end;
procedure TfrmPrintForm.LoadDBTree(Tree1: TdxDBTreeList);
begin
if (Tree1 = nil) or (Tree1.Datasource = nil) or (Tree1.Datasource.Dataset =
nil) then
Exit;
if not Tree1.Datasource.Dataset.Active then
Exit;
RMDBDataSet1.DataSource := Tree1.DataSource;
rmReport.DataSet := RMDBDataSet1;
if Tree1.Tag = 5 then
bPrintBar := True
else
bPrintBar := False;
SetTreeHeader(Tree1); //表头
SetTreeBody(Tree1); //表体
SetTreeSummary(Tree1); //表尾
end;
procedure TfrmPrintForm.SetTreeHeader(Tree1: TdxDBTreeList);
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;
if Tree1.ShowBands then //表头1
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Tree1.RowHeight + 4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -