Runtime tppLabel creation in a subreport
Hi all,
this is a little bit complex to explain so excuse me if this will be a long
text. My project is an activeX object that streams out a pdf-rendered report.
This report is built at runtime, merging several subreports loaded from file(s)
(filenames of the .rtm reports are taken from a table in a db).
All works fine (RB is very versatile on this POV) but i'm not able to do this:
In one of those subreports, i have an header band, and in the detail band one
subreport. The subreport have a jitpipeline associated that contains many
records and they are displayed correctly in the detail band of the subreport.
For each record of the subreport, i need to create at runtime a tppLabel in the
header band of the report that contains the subreport, and i can't do that....
I thought it was simple so i did it in this way:
In Global Declaration i created a variable to have a reference to the header band
var
{define a global variable}
headerReference: tppHeaderBand;
In Global OnCreate event i set the reference
procedure GlobalOnCreate;
begin
{set reference to header}
HeaderReference := Header;
end;
And finally in the DetailBeforePrint event of the subreport i wrote the code to
the labels
procedure DetailBeforePrint;
var
lbl: tppLabel;
begin
lbl := TppLabel.Create(HeaderReference);
lbl.name := 'Label' + jitppl['value'];
lbl.username := 'Label' + jitppl['value'];
{this is a little trick to set the owner}
lbl.owner := trick.owner;
lbl.Band := HeaderReference;
lbl.caption := 'Label' + jitppl['value'];
lbl.top := 10;
lbl.left := position + 10;
lbl.visible := true;
position := lbl.left;
end;
Note that i've read somewhere that the owner of tppLabel should be the Form so i
managed to use an invisible label named 'trick' to have the visibility of the
reference to the form object.
Unfortunately that don't work.. I always get an AV when i run the project.... If
i remove this line
lbl.owner := trick.owner;
no AV, but i don't see the labels.
Please help me.
Thanks for your help.
Gianantonio Dehò
this is a little bit complex to explain so excuse me if this will be a long
text. My project is an activeX object that streams out a pdf-rendered report.
This report is built at runtime, merging several subreports loaded from file(s)
(filenames of the .rtm reports are taken from a table in a db).
All works fine (RB is very versatile on this POV) but i'm not able to do this:
In one of those subreports, i have an header band, and in the detail band one
subreport. The subreport have a jitpipeline associated that contains many
records and they are displayed correctly in the detail band of the subreport.
For each record of the subreport, i need to create at runtime a tppLabel in the
header band of the report that contains the subreport, and i can't do that....
I thought it was simple so i did it in this way:
In Global Declaration i created a variable to have a reference to the header band
var
{define a global variable}
headerReference: tppHeaderBand;
In Global OnCreate event i set the reference
procedure GlobalOnCreate;
begin
{set reference to header}
HeaderReference := Header;
end;
And finally in the DetailBeforePrint event of the subreport i wrote the code to
the labels
procedure DetailBeforePrint;
var
lbl: tppLabel;
begin
lbl := TppLabel.Create(HeaderReference);
lbl.name := 'Label' + jitppl['value'];
lbl.username := 'Label' + jitppl['value'];
{this is a little trick to set the owner}
lbl.owner := trick.owner;
lbl.Band := HeaderReference;
lbl.caption := 'Label' + jitppl['value'];
lbl.top := 10;
lbl.left := position + 10;
lbl.visible := true;
position := lbl.left;
end;
Note that i've read somewhere that the owner of tppLabel should be the Form so i
managed to use an invisible label named 'trick' to have the visibility of the
reference to the form object.
Unfortunately that don't work.. I always get an AV when i run the project.... If
i remove this line
lbl.owner := trick.owner;
no AV, but i don't see the labels.
Please help me.
Thanks for your help.
Gianantonio Dehò
This discussion has been closed.
Comments
The form/datamodule upon which the TppReport component resides should be the
Owner of the report, bands, labels, etc. (This is Delphi standard for
TComponent descendants).
The Owner is passed to the constructor. (This is a standard for TComponent
descendants)
So perhaps try
myLabel := TppLabel.Create(myReport.Owner);
You need to create the Labels and DBTexts prior to calling Report.Print. You
can toggle the Visible property, but do not create/destroy elements while
the report is generating.
When you set properties such as Label.Top, the units are Report.Units. You
can also set spTop which is the screen pixel top.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com