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?
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
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;
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I'm trying to write a watermark text as big as possible. And centered on the page
http://rbwiki.digital-metaphors.com/delphi-code/formatting-delphi-code/how-to-manually-add-a-watermark-to-a-page/
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com