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

Aligning a TppDBImage component in report at runtime

edited May 2005 in General
Hi,

I have some generic code to align a TppDBImage in position left,centre or
right of page. I use the following code in the ppHeaderBandBeforePrint
event of Delphi code:

obj := ppReport1.FindUserObject('psLogo');
val := ppReport1.PrinterSetup.PaperWidth +
ppReport1.PrinterSetup.MarginLeft - ppReport1.PrinterSetup.MarginRight;

then

(obj as TppDBImage).Left := val - (obj as TppDBImage).Width; //for
right-align

OR

(obj as TppDBImage).Left := trunc((val - (obj as TppDBImage).Width)/2);
//for centre-align

However, I find that it doesn't centre or right-justify as it should, its
still out by a fair way Autosize is set to True. We are using
ReportBuilder 6.03. Any ideas on why this might not be working or
suggestions on a better way to do this?

Thanks

Alex

Comments

  • edited May 2005
    Found out that when calculating widths etc that the TppDBImage component has
    not yet resized itself. When does it do this ie at what stage can I use the
    component dimensions to calculate where it needs to be placed?

    Regards

    Alex

  • edited May 2005
    Hi Alex,

    What event are you trying to move the text object. Since this is a dynamic
    text component, I would recommend measureing the text every time you try to
    align it on the page. For instance inside the DetailBand.BeforePrint event,
    find out the width of the text using the Delphi method TextWidth with the
    proper font, then based on that value (which will need to be converted into
    report units) move the text with your equation below. Note: Adding
    ppPrintr to your uses clause will give you access to the Printer.Canvas
    property.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2005
    Hi Nico,

    It is not a text object, its a TppDBImage and therefore a graphic is
    assigned to it from a database field. It is in fact a company logo. Until
    the component is filled with the image (from database) I do not know what
    size it will be. This company logo needs to, for example, be left, centre
    ot right-aligned acording to a user's setting. The TppDBImage component is
    placed in the overlay band. I have tried my code in a couple of events to
    no avail. Any suggestions on a way to achieve my desired outcome?

    Thanks

    Alex
  • edited May 2005
    Hi Alex,

    Sorry, I missread your first post. Try using the OnDrawCommandCreate event
    to find the width of the current image. By this time, you should be able to
    retrieve the actual width of the updated image and use that to position the
    draw command. All the values are calculated in microns when working with
    draw commands so you will need to take a look at the conversion utilities
    located in the ppUtils.pas file.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.