New Blog Post: RESTful Reporting

AV when adding ppLabet at runtime

Hi

I'm trying to add a label (watermark) runtime. But when rendering the report to a PDF file I get an AV.

How to Reproduce:

An empty form with a button and an empty ppReport (content or not doesn't make a difference)

Add a click handler to the button:

procedure TForm30.Button1Click(Sender: TObject);
var
lPDFDevice: TppPDFDevice;
begin
lPDFDevice := TppPDFDevice.Create(nil);
lPDFDevice.PDFSettings.OpenPDFFile := True;
lPDFDevice.FileName := TppFileUtils.GetApplicationFilePath + 'myReport.PDF';
lPDFDevice.Publisher := ppReport1.Publisher;
ppReport1.PrintToDevices;
end;

Add an implement an OnEndPage event:

procedure TForm30.ppReport1EndPage(Sender: TObject);
var
ppLabel: TppLabel;
begin

ppLabel := TppLabel.Create(nil);

ppLabel.Text := 'Kopi';
ppLabel.AutoSize := True;
ppLabel.Angle := 315;
ppLabel.Transparent := True;
ppLabel.Font.Size := 20;
ppLabel.Font.Color := clBtnFace;

ppReport1.Engine.Page.InsertChild(0, ppLabel);
end;


What am I doing wrong?

Comments

  • UPDAE: If using a TppDrawText I get en "invalid pointer operation" exception when closing the main form

    procedure TForm30.ppReport1EndPage(Sender: TObject);
    var
    lDrawText: TppDrawText;
    lPage: TppPage;
    begin
    lDrawText := TppDrawText.Create(nil);

    lPage := ppReport1.Engine.Page;
    lDrawText.Left := lPage.PageDef.mmMarginLeft;
    lDrawText.Top := lPage.PageDef.mmMarginTop;
    lDrawText.Width := lPage.PageDef.mmPrintableWidth;
    lDrawText.Height := lPage.PageDef.mmPrintableHeight;

    lDrawText.Angle := 315;
    lDrawText.Font.Color := clLtGray;
    lDrawText.Font.Size := 300;
    lDrawText.Alignment := taCenter;
    lDrawText.Transparent := True;
    lDrawText.IsMemo := false;
    lDrawText.Autosize := True;
    lDrawText.Text := 'Copy';
    lDrawText.Page := lPage;
    ppReport1.Engine.Page.InsertChild(0, lDrawText);
    end;
  • Hi Jens,

    By assigning the TppDrawText.Page and also inserting it into the page, you are essentially adding the draw command twice, which will cause errors when destroying. Try removing the lDrawText.Page := lPage; line and see if that solves the problem.




    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 7
    That solved the problem wirh lpDrawText but it doesn't solve the problem with a ppLabel.

    I'm trying to write a watermark text as big as possible. And centered on the page
  • Take a look at the following article/example on adding a watermark to a page. You will want to size the draw command to the size of the page to make the text as large as possible (sizing font is up to you however). You can do this using the Report.Printer.PageDef.mmPrintableHeight or mmPrintableWidth properties.

    http://rbwiki.digital-metaphors.com/delphi-code/formatting-delphi-code/how-to-manually-add-a-watermark-to-a-page/



    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Thank you very much. I have looked at that example, My problem are to calculate the maximum font size and then center the label. Or whatever, that's why I wanted to use a label because it updates height and width when increasing the font size. TppDrawText doesn't
  • Hi Jens,

    An Autosized label/drawtext would not give you the effect you are after. Autosize, resizes the control's bounding rectangle to fit the text inside, it does not adjust the font size to fill a given area. What you need is an auto scaling feature. We will consider something like this for a later release of ReportBuilder.

    Currently you will need to measure the text and compare it to the space available to find the largest font that will fit.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
Sign In or Register to comment.