Question
“How can I format each line with something like ‘Value…..’ such that ‘.’ characters are used to fill the remaining space?”
Solution
This example shows how to Use a Variable and its OnCalc event to append the appropriate number of ‘.’to each line.
Download: FillLineWithDots.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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
uses ppTypes, ppUtils; procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant); var ldMaxWidth: Double; liDotCount: Integer; lCanvas: TCanvas; lsValue: String; begin // space available (report.Units are utInches here) ldMaxWidth := 2; lsValue := ppDBPipeline1['ShipVia']; // use printer canvase to perform calculations lCanvas := ppReport1.Printer.Canvas; lCanvas.Font := ppVariable1.Font; // calc number of dots that fit to the right of the text liDotCount := CaclulateDots(lsValue, ldMaxWidth, lCanvas, ppReport1.Printer); // append dots to the string value Value := lsValue + StringOfChar('.', liDotCount); end; function TForm1.CaclulateDots(aLeftText: String; aMaxWidth: Double; aCanvas: TCanvas; aPrinter: TppPrinter): Integer; var ldValueWidthInInches: Double; ldMaxAvailableDotWidth: Double; ldDotWidthInInches: Double; begin // calc text width in inches ldValueWidthInInches := aCanvas.TextWidth(aLeftText) / aPrinter.PixelsPerInch.X; // calc dot width in inches ldDotWidthInInches := aCanvas.TextWidth('.') / aPrinter.PixelsPerInch.X; // calc available width ldMaxAvailableDotWidth := aMaxWidth - ldValueWidthInInches; // calc number of dots Result := Trunc(ldMaxAvailableDotWidth / ldDotWidthInInches); end; |