【问题标题】:Delphi Report Builder Create a Runtime Component Not show a new Label on ScreenDelphi Report Builder 创建运行时组件不在屏幕上显示新标签
【发布时间】:2016-10-05 18:45:28
【问题描述】:

我在报表生成器中创建一个组件以在报表上创建一组标签, 部分代码如下:

for I := 0 to 20 do begin
            Txt                 := TppLabel.Create(Report);
            Txt.Caption         := GradePipeLine.GetFieldAsString('Grade') ;
            Txt.Left            := StartLeft;
            Txt.Top             := StartTop;
            Txt.Band            := Band;
            Txt.AutoSize        := AutoSize;
            Txt.Width           := TmpWidth;
            Txt.Font            := Font;
            Txt.TextAlignment   := TextAlignment;
            Txt.Border          := Border;
            Txt.Transparent     := true;
            Txt.Tag             := -50000;
            StartLeft           := TmpEspacamento + StartLeft;
end;

此代码有效,但有问题, 当我第一次在屏幕上显示报告时,此代码创建的新标签不显示,但如果我关闭并打开预览屏幕,则创建的新 ppLabels 显示正常。 我在 ppReport 上的 BeforePrint 事件中调用此代码 有一些命令可以强制 ppReport 更新此 ppLabel 或强制使用此新标签重新加载所有报告?

【问题讨论】:

    标签: delphi runtime reportbuilder


    【解决方案1】:

    嗯,我创建了一个小样本(见下文),它对我有用。您能否创建一个类似的示例来显示问题?

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ppBands, ppCache, ppClass,
      ppDesignLayer, ppParameter, ppComm, ppRelatv, ppProd, ppReport, Vcl.StdCtrls,
      ppEndUsr, ppPrnabl, ppCtrls;
    
    type
      TForm1 = class(TForm)
        ppReport1: TppReport;
        ppParameterList1: TppParameterList;
        ppDesignLayers1: TppDesignLayers;
        ppDesignLayer1: TppDesignLayer;
        ppHeaderBand1: TppHeaderBand;
        ppDetailBand1: TppDetailBand;
        ppFooterBand1: TppFooterBand;
        Button1: TButton;
        ppDesigner1: TppDesigner;
        procedure Button1Click(Sender: TObject);
        procedure ppReport1BeforePrint(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    uses
      ppIniStorage;
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      LDesigner: TppDesigner;
    begin
      LDesigner := TppDesigner.Create(nil);
      try
        LDesigner.Caption := 'Invoice Report Designer';
        LDesigner.IniStorageType := TppIniNone.ClassDescription;
    
        LDesigner.Report := ppReport1;
        LDesigner.ShowModal;
      finally
        LDesigner.Free;
      end;
    end;
    
    procedure TForm1.ppReport1BeforePrint(Sender: TObject);
    const
      TmpEspacamento = 0.7;
      StartTop = 0.1875;
      AutoSize = True;
      TmpWidth = 0.5;
    var
      I: Integer;
      Txt: TppLabel;
      StartLeft: Double;
    begin
      StartLeft := 0.083300002;
    
      for I := 0 to 2 do
      begin
                Txt                 := TppLabel.Create(ppReport1);
                Txt.Caption         := Format('Label %d', [I]);//GradePipeLine.GetFieldAsString('Grade') ;
                Txt.Left            := StartLeft;
                Txt.Top             := StartTop;
                Txt.Band            := ppHeaderBand1;
                Txt.AutoSize        := AutoSize;
                Txt.Width           := TmpWidth;
                Txt.Font            := Font;
                //Txt.TextAlignment   := TextAlignment;
                //Txt.Border          := Border;
                Txt.Transparent     := true;
                Txt.Tag             := -50000;
                StartLeft           := TmpEspacamento + StartLeft;
      end;
    end;
    
    end.
    

    和 DFM 文件

    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 290
      ClientWidth = 554
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Button1: TButton
        Left = 12
        Top = 8
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
      object ppReport1: TppReport
        PrinterSetup.BinName = 'Default'
        PrinterSetup.DocumentName = 'Report'
        PrinterSetup.PaperName = 'Letter'
        PrinterSetup.PrinterName = 'Default'
        PrinterSetup.SaveDeviceSettings = False
        PrinterSetup.mmMarginBottom = 6350
        PrinterSetup.mmMarginLeft = 6350
        PrinterSetup.mmMarginRight = 6350
        PrinterSetup.mmMarginTop = 6350
        PrinterSetup.mmPaperHeight = 279400
        PrinterSetup.mmPaperWidth = 215900
        PrinterSetup.PaperSize = 1
        ArchiveFileName = '($MyDocuments)\ReportArchive.raf'
        BeforePrint = ppReport1BeforePrint
        DeviceType = 'Screen'
        DefaultFileDeviceType = 'PDF'
        EmailSettings.ReportFormat = 'PDF'
        LanguageID = 'Default'
        OutlineSettings.CreateNode = True
        OutlineSettings.CreatePageNodes = True
        OutlineSettings.Enabled = True
        OutlineSettings.Visible = True
        PDFSettings.EmbedFontOptions = [efUseSubset]
        PDFSettings.EncryptSettings.AllowCopy = True
        PDFSettings.EncryptSettings.AllowInteract = True
        PDFSettings.EncryptSettings.AllowModify = True
        PDFSettings.EncryptSettings.AllowPrint = True
        PDFSettings.EncryptSettings.Enabled = False
        PDFSettings.FontEncoding = feAnsi
        PDFSettings.ImageCompressionLevel = 25
        RTFSettings.DefaultFont.Charset = DEFAULT_CHARSET
        RTFSettings.DefaultFont.Color = clWindowText
        RTFSettings.DefaultFont.Height = -13
        RTFSettings.DefaultFont.Name = 'Arial'
        RTFSettings.DefaultFont.Style = []
        TextFileName = '($MyDocuments)\Report.pdf'
        TextSearchSettings.DefaultString = '<FindText>'
        TextSearchSettings.Enabled = True
        XLSSettings.AppName = 'ReportBuilder'
        XLSSettings.Author = 'ReportBuilder'
        XLSSettings.Subject = 'Report'
        XLSSettings.Title = 'Report'
        Left = 148
        Top = 72
        Version = '14.08'
        mmColumnWidth = 0
        object ppHeaderBand1: TppHeaderBand
          Background.Brush.Style = bsClear
          mmBottomOffset = 0
          mmHeight = 13229
          mmPrintPosition = 0
        end
        object ppDetailBand1: TppDetailBand
          Background1.Brush.Style = bsClear
          Background2.Brush.Style = bsClear
          mmBottomOffset = 0
          mmHeight = 13229
          mmPrintPosition = 0
        end
        object ppFooterBand1: TppFooterBand
          Background.Brush.Style = bsClear
          mmBottomOffset = 0
          mmHeight = 13229
          mmPrintPosition = 0
        end
        object ppDesignLayers1: TppDesignLayers
          object ppDesignLayer1: TppDesignLayer
            UserName = 'Foreground'
            LayerType = ltBanded
            Index = 0
          end
        end
        object ppParameterList1: TppParameterList
        end
      end
      object ppDesigner1: TppDesigner
        Caption = 'ReportBuilder'
        DataSettings.SessionType = 'BDESession'
        DataSettings.AllowEditSQL = False
        DataSettings.GuidCollationType = gcString
        DataSettings.IsCaseSensitive = True
        DataSettings.SQLType = sqBDELocal
        Position = poScreenCenter
        IniStorageType = 'IniFile'
        IniStorageName = '($LocalAppData)\RBuilder\RBuilder.ini'
        WindowHeight = 400
        WindowLeft = 100
        WindowTop = 50
        WindowWidth = 600
        Left = 280
        Top = 164
      end
    end
    

    【讨论】:

      【解决方案2】:

      我认为问题出在插入创建标签的代码的地方。我的建议是将此代码放在ppReport1InitializeParameters 事件中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-03
        • 2013-02-21
        • 2011-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-01
        相关资源
        最近更新 更多