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

index out of bounds

edited January 2005 in General
In ppPDFWrappedText unit, there is a bug only occurs in some situation.

" index(0) out of bounds "

{TppPDFWrappedText.WriteCenterRightText

Write Center or Right aligned text to the content stream. }

procedure TppPDFWrappedText.WriteCenterRightText;
var
ldLastOffset: Double;
liIndex: Integer;
lsText: String;
ldTextWidth: Double;
begin

FRunningOffset := 0;

{Write the first line in the memo/wrapped label}
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[0]);
//<------------// Bug is here
ldTextWidth := TextWidthPoints(FWrappedText.Strings[0]);
ldLastOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, 0);
FLeftOffset := FLeftOffset + ldLastOffset;
WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');

{Base the remaining lines on the initial offset}
for liIndex := 1 to FWrappedText.Count - 1 do
begin
lsText := TppPDFUtils.ProcessText(FWrappedText.Strings[liIndex]);
ldTextWidth := TextWidthPoints(FWrappedText.Strings[liIndex]);

FLeftOffset := ProcessCenterRightJustification(lsText,
DrawTextCommand.TextAlignment, ldTextWidth, ldLastOffset);
FBottomOffset := -FLineHeight;

WriteMSLine(MemoryStream, ExtToStr(FLeftOffset) + ' ' +
ExtToStr(FBottomOffset) + ' Td');
WriteMSLine(MemoryStream, '(' + lsText + ') Tj');

ldLastOffset := FLeftOffset;

end;

WriteMSLine(MemoryStream, 'ET');

end;

When the 2nd time this function is called, sometime the FWrappedText is
empty, then it cause the problem.

I make some changes for this procedure to test the 'Empty' situation, the
bug is gone and the PDF file is good as expected.

Comments

This discussion has been closed.