⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_pdbgrid.pas

📁 这是一个功能强大
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      liView.LeftFrame.Visible := True;
      liView.TopFrame.Visible := True;
      liView.RightFrame.Visible := True;
      liView.BottomFrame.Visible := True;
    end
    else
    begin
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
    end;

    liView.spLeft := tmpx;
    liView.spTop := 0;
    liView.spWidth := liDBGrid.Columns[aIndex].Width + 1;
    liView.spHeight := liRowHeight;
    liView.Memo.Text := Format('[%s."%s"]', [THackFormReport(aFormReport).AddRMDataSet(liDBGrid.DataSource.DataSet).Name, liDBGrid.Columns[aIndex].FieldName]);
    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liDBGrid.Columns[aIndex].Color;

    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.spWidth;
    if Assigned(aFormReport.OnAfterCreateGridObjectEvent) then
      aFormReport.OnAfterCreateGridObjectEvent(aControl, liDBGrid.Columns[aIndex].FieldName, liView);

    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
    end;
    _DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  procedure _DrawFixedColHeader;
  var
    i: Integer;
  begin
    for i := 0 to aFormReport.GridFixedCols - 1 do
    begin
      if i < liDBGrid.Columns.Count then
        _MakeOneHeader(i);
    end;
  end;

  procedure _DrawFixedColDetail;
  var
    i: Integer;
  begin
    for i := 0 to aFormReport.GridFixedCols - 1 do //表体
    begin
      {$IFDEF COMPILER4_UP}
      if not liDBGrid.Columns[i].Visible then
        Continue;
      {$ENDIF}
      if i < liDBGrid.Columns.Count then
        _MakeOneDetail(i);
    end;
  end;

begin
//  if aFormReport.DrawOnPageFooter then Exit;

  FParentReport := aFormReport.Report;
  liDBGrid := THackDBGrid(aControl);
  if (liDBGrid.Datasource = nil) or (liDBGrid.Datasource.Dataset = nil) then Exit;
  if not liDBGrid.Datasource.Dataset.Active then Exit;

  FDBGrid := liDBGrid;
  if (rmgoSelectedRecordsOnly in aFormReport.ReportOptions) and
    (liDBGrid.SelectedRows.Count > 0) then //只打印选择的记录
  begin
    AutoFree := False;
    aFormReport.Report.OnBeforePrintBand := OnBeforePrintBandEvent;
  end;

  liRowHeight := liDBGrid.DefaultRowHeight + 4;
  if aFormReport.MasterDataBandOptions.Height > 0 then
    liRowHeight := aFormReport.MasterDataBandOptions.Height;

  aFormReport.DrawOnPageFooter := True;
  aFormReport.GridTop := THackFormReport(aFormReport).OffsY + aControl.Top;
  aFormReport.GridHeight := aControl.Height;
  lNextTop := aControl.Top + THackFormReport(aFormReport).OffsY;
  aFormReport.MainDataSet := THackFormReport(aFormReport).AddRMDataSet(liDBGrid.DataSource.DataSet);
  liGridTitleHeight := 0;
  tmpx := 0;
  for i := 0 to liDBGrid.Columns.Count - 1 do
  begin
    {$IFDEF COMPILER4_UP}
    if liDBGrid.Columns[i].Visible then
      {$ENDIF}
      tmpx := tmpx + liDBGrid.Columns[i].Width + 1;
  end;

  if (TDBGridOption(dgTitles) in liDBGrid.Options) and (rmgoGridNumber in aFormReport.ReportOptions) then
    tmpx := tmpx + RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;

  if (aFormReport.PrintControl = aControl) or (tmpx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then
    THackFormReport(aFormReport).FormWidth[0] := IntToStr(tmpx + (THackFormReport(aFormReport).OffsX + aControl.Left) * 2);

  // 表头
  liPage := TRMReportPage(aFormReport.Report.Pages[0]);
  if TDBGridOption(dgTitles) in liDBGrid.Options then //表头
  begin
    liFlagFirstColumn := True;
    liGridTitleHeight := liDBGrid.RowHeights[0] + 4;
    tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
    if rmgoGridNumber in aFormReport.ReportOptions then
    begin
      liView := RMCreateObject(rmgtMemo, '');
      liView.ParentPage := liPage;
      liView.spLeft := tmpx;
      liView.spTop := lNextTop;
      liView.spWidth := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
      liView.spHeight := liGridTitleHeight;
      liView.Memo.Add(aFormReport.GridNumOptions.Text);
      TRMMemoView(liView).VAlign := rmvCenter;
      TRMMemoView(liView).HAlign := rmhCenter;
      if (rmgoGridLines in aFormReport.ReportOptions) and (TDBGridOption(dgColLines) in liDBGrid.Options) then
      begin
        liView.LeftFrame.Visible := True;
        liView.TopFrame.Visible := True;
        liView.RightFrame.Visible := True;
        liView.BottomFrame.Visible := True;
      end
      else
      begin
        liView.LeftFrame.Visible := False;
        liView.TopFrame.Visible := False;
        liView.RightFrame.Visible := False;
        liView.BottomFrame.Visible := False;
      end;

      aFormReport.ColumnHeaderViews.Add(liView);
      tmpx := tmpx + liView.spWidth;

      if rmgoDoubleFrame in aFormReport.ReportOptions then
      begin
        if liFlagFirstColumn then
          liView.LeftFrame.Width := 2;
        liView.TopFrame.Width := 2;
      end;
      liFlagFirstColumn := False;
    end;

    tmpx0 := tmpx;
    liNum := 0;
    for i := 0 to liDBGrid.Columns.Count - 1 do
    begin
      {$IFDEF COMPILER4_UP}
      if not liDBGrid.Columns[i].Visible then
        Continue;
      {$ENDIF}
      if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
      begin
        if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liDBGrid.Columns[i].Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
        begin
          liNum := 0;
          liFlagFirstColumn := True;
          if rmgoDoubleFrame in aFormReport.ReportOptions then
            liView.RightFrame.Width := 2;

          THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
          THackFormReport(aFormReport).AddPage;
          THackFormReport(aFormReport).FormWidth.Add('0');
          liPage := TRMReportPage(aFormReport.Report.Pages[aFormReport.Report.Pages.Count - 1]);
          tmpx := tmpx0;
          liFlagFirstColumn := True;
          _DrawFixedColHeader;
        end;
      end;

      _MakeOneHeader(i);
      Inc(liNum);
    end;

    liFlagFirstColumn := True;
    if rmgoDoubleFrame in aFormReport.ReportOptions then
      liView.RightFrame.Width := 2;
  end;

  if THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);

  // 表体
  liPageNo := 0;
  liPage := TRMReportPage(aFormReport.Report.Pages[0]);
  tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
  liFlagFirstColumn := True;
  if (dgTitles in liDBGrid.Options) and (rmgoGridNumber in aFormReport.ReportOptions) then
  begin
    liView := RMCreateObject(rmgtMemo, '');
    liView.ParentPage := liPage;
    liView.spLeft := tmpx;
    liView.spTop := 0;
    liView.spWidth := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
    liView.spHeight := liRowHeight;
    liView.Memo.Add('[_RM_Line]');
    TRMMemoView(liView).Stretched := rmgoStretch in aFormReport.ReportOptions;
    TRMMemoView(liView).VAlign := rmvCenter;
    TRMMemoView(liView).HAlign := rmhCenter;
    if (rmgoGridLines in aFormReport.ReportOptions) and (TDBGridOption(dgColLines) in liDBGrid.Options) then
    begin
      liView.LeftFrame.Visible := True;
      liView.TopFrame.Visible := True;
      liView.RightFrame.Visible := True;
      liView.BottomFrame.Visible := True;
    end
    else
    begin
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
    end;

    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.spWidth;

    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
    end;
    _DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  tmpx0 := tmpx;
  liPage := aPage;
  liNum := 0;
  for i := 0 to liDBGrid.Columns.Count - 1 do //表体
  begin
    {$IFDEF COMPILER4_UP}
    if not liDBGrid.Columns[i].Visible then
      Continue;
    {$ENDIF}
    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liDBGrid.Columns[i].Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.Width := 2;

        THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(tmpx);
        Inc(liPageNo);
        if liPageNo >= aFormReport.Report.Pages.Count then
        begin
          THackFormReport(aFormReport).AddPage;
          THackFormReport(aFormReport).FormWidth.Add('0');
        end;
        liPage := TRMReportPage(aFormReport.Report.Pages[liPageNo]);
        tmpx := tmpx0;
        liFlagFirstColumn := True;
        _DrawFixedColDetail;
      end;
    end;

    _MakeOneDetail(i);
    Inc(liNum);
  end;

  if liNum > 0 then
  begin
    liFlagFirstColumn := True;
    if rmgoDoubleFrame in aFormReport.ReportOptions then
      liView.RightFrame.Width := 2;
  end;

  if THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMFormPrintStringGrid}
type
  THackGrid = class(TCustomGrid)
  end;

constructor TRMFormPrintStringGrid.Create;
begin
  inherited Create;
  AutoFree := False;
end;

destructor TRMFormPrintStringGrid.Destroy;
begin
  if FUserDataset <> nil then
  begin
    FUserDataset.Free;
    FUserDataset := nil;
  end;
  if FList <> nil then
  begin
    FList.Free;
    FList := nil;
  end;
  inherited Destroy;
end;

procedure TRMFormPrintStringGrid.SetMemos;
var
  i: Integer;
  liView: TRMMemoView;
  s: string;
  liHeight: Integer;

  procedure AssignFont(aFont: TFont);
  var
    liSaveColor: TColor;
  begin
    liSaveColor := liView.Font.Color;
    liView.Font.Assign(aFont);
    if not (rmgoUseColor in FFormReport.ReportOptions) then
      liView.Font.Color := liSaveColor;
  end;

begin
  liHeight := THackGrid(FGrid).RowHeights[FCurrentRow];
  //	RMReport.Pages[0].FindObject(FDetailBandName).spHeight := liHeight;
  for i := 0 to FList.Count - 1 do
  begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -