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

Dynamic Caption Setting and autosizing for TppLabel, is it possible ?

edited October 2001 in General
Hello,

I am working on ReportBuilder 6.02 Standard, Windows 2000 and
Delphi 5.0.

I need to change the caption of a label during the beforePrint or
beforeGenerate events.

The label, even when set to autosize, would not grow in
width after its caption have been changed.

I am using (or trying to use) the new width of this label
to align another label to its right side.

I noticed that in the TppPrintable.setCaption method you
call adjustBounds and in there the code is checking if the report is
printing
and that is why my label does not get wider or thinner.

what can I do ?!?! this should be very simple or am I missing something ??

Should I use another component for dynamic captions ?

Thanks in advance,

Roy Waxman.

Comments

  • edited October 2001
    Perhaps, it may be easier to use a single TppVariable and code its OnCalc
    event handler to concatenate the strings together, instead of using mutiple
    labels and trying to resize them and align them together.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited October 2001
    Hello,

    Thanks for the reply,

    This cannot be done by concatenating strings because each label has
    different font styles.
    one label is the caption (bold) and the other is the data. We must use 2
    labels.
    We found a strange solution for this by using another RB Report component
    with only a label on it
    just to calculate the width for a certain caption.

    Bye.

  • edited October 2001
    Here is the BeforePrint of the detail band where ppLabel2 is set to the
    value of the right of ppLabel1. I used the printer canvas to get the text
    width, then converted it to my report units which are in inches.

    uses
    ppUtils, ppTypes;

    procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
    var
    ldTextWidth: Double;
    liWidth: Integer;
    lCanvas: TCanvas;
    begin

    ppLabel1.Caption := 'Caption 1';
    ppLabel2.Caption := 'Caption 2';

    lCanvas := ppReport1.Printer.Canvas;
    lCanvas.Font := ppLabel1.Font;

    liWidth := lCanvas.TextWidth(ppLabel1.Caption);

    {convert printer pixels to microns}
    ldTextWidth := ppToMMThousandths(liWidth, utPrinterPixels, pprtHorizontal,
    ppReport1.Printer);

    {convert microns to report units (inches)}
    ldTextWidth := ppFromMMThousandths(Round(ldTextWidth), utInches,
    pprtHorizontal, ppReport1.Printer);

    ppLabel2.Left := ppLabel1.Left + ldTextWidth;

    end;


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited October 2001
    Have you considered replacing the labels with a richedit. That would allow
    you to format the text as desired and position the second label using a tab.


    ------------------------------------
    Bruce Roberts
    Roberts Browne Limited
    RBAddOn Components for Report Builder
    http://www.bancoems.com/rbaddon.htm
This discussion has been closed.