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

Calculating TppDBText width in code

edited July 2001 in General
I've just created my first report from code - very easy!

I am creating a report from an unknown datasource so am using the
query.fields properties to build the necessary headerline labels and
dataline TppDBText objects.

However, I am having trouble calculating the maximum width for each
TppDBText object.

I know the field size of the data but need a way of calculating the maximum
width to accomodate all data.

In other words, is there a simple formula for calculating the screen pixel
width of a TppDBText object, dependent on data field size and font size?

Regards

Pete Colson

Comments

  • edited July 2001
    You can convert inches to screen pixels by using these two functions in
    ppUtils.pas. Include ppTypes in the uses clause as well.

    Thousandths of a millimeter is the same as microns.

    liMicrons := ppToMMThousandths(1.5, utInches, pprtHorizontal,
    ppReport1.Printer);
    then
    liScreenPixels := ppFromMMThousandths(liMicrons, utScreenPixels,
    pprtHorizontal, ppReport1.Printer);


    You can get the printable width on the page from the report dynamically (in
    microns) with
    ppReport1.PrinterSetup.PageDef.mmPrintableWidth

    The margins can be found with (in microns)
    ppReport1.PrinterSetup.PageDef.mmMarginRight
    ppReport1.PrinterSetup.PageDef.mmMarginLeft

    To get the width a text, use the printer canvas to call TextWidth, as this
    is the canvas that RB will use to generate on.
    liTextWidth := ppReport1.Printer.Canvas.TextWidth(lsMyTextField);
    This will be in printer pixels not screen pixels. So, the above ppUtils
    conversion routines should use utPrinterPixels in the call.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.