On platform: Lazarus 1.8.4, FPC 3.0.4, OS: Windows Server 2016
I encountered this range checking error while doing a
.LoadFromString() using version 11.8 THTMLViewer
[Debugger Exception Notification]
Project RUBI - Medical raised exception class 'RunError(201)'.
In file '..\source\ReadHTML.pas' at line 1672
[Ignore this exception type]
[Break] [Continue]
-------------------------------------------------
// Original code:
procedure TCellManager.AddCell(Row: Integer; CellObj: TCellObj);
{Adds this cell to the specified row}
var
I, J, K, Span: Integer;
S1: ThtString;
begin
{make sure there's enough rows to handle any RowSpan for this cell}
while Count < Row + CellObj.RowSpan do
Add(StringOfChar('o', Table.ColSpecs.Count));
I := Pos('o', Strings[Row]); {where we want to enter this cell}
K := I;
if I > 0 then {else it's beyond the ColInfo and we're not interested}
for J := Row to Row + CellObj.RowSpan - 1 do {do for all rows effected}
begin
I := K;
Span := CellObj.ColSpan; {need this many columns for this cell}
S1 := Strings[J];
repeat
if S1[I] = 'o' then // <--- The eighth pass I = 2, but the string is just 'x'
begin
S1[I] := 'x';
Inc(I);
Dec(Span);
end
else
Break;
until Span = 0;
Strings[J] := S1;
if Span > 0 then {there's a conflict, adjust ColSpan to a practical value}
CellObj.ColSpan := CellObj.ColSpan - Span;
end;
end;
Corrected by:
My changes applied:
procedure TCellManager.AddCell(Row: Integer; CellObj: TCellObj);
{Adds this cell to the specified row}
var
I, J, K, Span: Integer;
S1: ThtString;
begin
{make sure there's enough rows to handle any RowSpan for this cell}
while Count < Row + CellObj.RowSpan do
Add(StringOfChar('o', Table.ColSpecs.Count));
I := Pos('o', Strings[Row]); {where we want to enter this cell}
K := I;
if I > 0 then {else it's beyond the ColInfo and we're not interested}
for J := Row to Row + CellObj.RowSpan - 1 do {do for all rows effected}
begin
I := K;
Span := CellObj.ColSpan; {need this many columns for this cell}
S1 := Strings[J];
repeat
if I > Length(S1) then // This line added by Kevin Morris 2019-Mar-03
Dec(I); // This line added by Kevin Morris 2019-Mar-03
if S1[I] = 'o' then
begin
S1[I] := 'x';
Inc(I);
Dec(Span);
end
else
Break;
until Span = 0;
Strings[J] := S1;
if Span > 0 then {there's a conflict, adjust ColSpan to a practical value}
CellObj.ColSpan := CellObj.ColSpan - Span;
end;
end;
Error goes away, but not sure if this is the best solution.