Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

change pplabel caption runtime into designer

edited February 2010 in General
Hello,
I'm using D7 with RB 9.03 ent. ed.

In my program I need to allow users to modify the rtm before print, so i prepare the designer with delphi code like this:

ppReport.Template.FileName := 'c:\test.rtm';
ppReport.Template.LoadFromFile;
ppDesigner1.Report := ppReport;
// some code that change labels captions into loaded rtm
ppDesigner1.ShowModal;

How do I change the caption of some tpplabels inside the loaded test.rtm before open the designer?

I taken a snippet code from the wiki, the code to traverse report in runtime all seems to works fine, the pplabels are found and changed... but after, when I invoke the showmodal of designer the labels are shown unchanged..
Here's my function (tested, it works):

function TdmPrint2.FindppLabelByUserName(aReport: TppCustomReport; AUserName : string) : TppLabel;
var
liBand: Integer;
liObject: Integer;
lObject: TppComponent;
begin
result := nil;
for liBand := 0 to aReport.BandCount-1 do
for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
begin
lObject := aReport.Bands[liBand].Objects[liObject];
//if the object is a subreport make a recursive call to this routine.
if (lObject is TppSubreport) then begin
result := FindppLabelByUserName(TppSubreport(lObject).Report,AUserName);
if Assigned(Result) then Exit;
end;
if lObject.UserName = AUserName then begin
Result := (lObject as TppLabel);
exit;
end;
end;
end;

And I use that with this:
theLabel := FindppLabelByUserName(The_Report_Loaded,aLabel.UserName);
if Assigned(theLabel) then theLabel.Caption := aCaption;

thank you.

--
Morde

Comments

  • edited February 2010
    Hi Morde,

    In my testing with code similar to the code you have below, I was able to
    successfully change the caption of a label before designing.

    procedure TForm1.Button1Click(Sender: TObject);
    var
    lLabel: TppLabel;
    begin

    ppReport1.Template.FileName := 'test.rtm';
    ppReport1.Template.LoadFromFile;

    lLabel := GetLabelForUserName('Label1');

    lLabel.Caption := 'NewCaption';

    ppDesigner1.Report := ppReport1;
    ppDesigner1.ShowModal;
    end;

    function TForm1.GetLabelForUserName(aUserName: String): TppLabel;
    var
    liBand: Integer;
    liObject: Integer;
    lObject: TppComponent;

    begin

    for liBand := 0 to ppReport1.BandCount-1 do

    for liObject := 0 to ppReport1.Bands[liBand].ObjectCount-1 do
    begin
    lObject := ppReport1.Bands[liBand].Objects[liObject];

    //if the object is a subreport make a recursive call to this
    routine.
    if (lObject is TppSubreport) then
    Result := GetLabelForUserName(aUserName);

    if (lObject is TppLabel) and (TppLabel(lObject).UserName =
    aUserName) then
    Result := TppLabel(lObject);

    end;

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2010
    Nel suo scritto precedente, Nico Cizik (Digital Metaphors) ha
    sostenuto:

    I apologize Nico, during refactoring i discovered that in another
    method a loadfromfile too overwrite all runtime modification.. just
    before showmodal of the editor.. DOH! :-)

    Bye

    --
    Morde
This discussion has been closed.