Question
“How do I calculate the current position of a component after it has been generated to a report?”
Solution
Use the OnDrawCommandCreate event of the component to get the current position on the page, then use the conversion utility functions in ppUtils.pas to convert the value into report units.
Download: CalcPrintPosition.zip
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
uses ppTypes, ppUtils; procedure TForm1.ppLabel2DrawCommandCreate(Sender, aDrawCommand: TObject); var lDrawTextCommand: TppDrawText; lPrintPosInInches: Double; lBottomPosInMicrons: Integer; begin // Each time an object generates on a page, it creates a draw command // This is the Label2.OnDrawCommandCreate, which fires each time the // label generates on a page. The DrawCommand contains a desscription what will // be drawn to the page, the location, font, etc. // type cast to TppDrawText lDrawTextCommand := TppDrawText(aDrawCommand); // calc bottom position in microns lBottomPosInMicrons := lDrawTextCommand.Top + lDrawTextCommand.Height; // convert to inches lPrintPosInInches := ppFromMMThousandths(lBottomPosInMicrons, utInches, pprtVertical, nil); // display on the report lDrawTextCommand.Text := FormatFloat('0.000', lPrintPosInInches); end; |