Recent

Author Topic: THTMLViewer throws error RunError 201at ReadHTML.pas at line 1672  (Read 1785 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 475
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]
 
-------------------------------------------------

Code: Pascal  [Select][+][-]
  1.  
  2. // Original code:
  3.  
  4. procedure TCellManager.AddCell(Row: Integer; CellObj: TCellObj);
  5. {Adds this cell to the specified row}
  6. var
  7.   I, J, K, Span: Integer;
  8.   S1: ThtString;
  9. begin
  10. {make sure there's enough rows to handle any RowSpan for this cell}
  11.   while Count < Row + CellObj.RowSpan do
  12.     Add(StringOfChar('o', Table.ColSpecs.Count));
  13.   I := Pos('o', Strings[Row]); {where we want to enter this cell}
  14.   K := I;
  15.   if I > 0 then {else it's beyond the ColInfo and we're not interested}
  16.     for J := Row to Row + CellObj.RowSpan - 1 do {do for all rows effected}
  17.     begin
  18.       I := K;
  19.       Span := CellObj.ColSpan; {need this many columns for this cell}
  20.       S1 := Strings[J];
  21.       repeat
  22.         if S1[I] = 'o' then  // <--- The eighth pass I = 2, but the string is just 'x'
  23.         begin
  24.           S1[I] := 'x';
  25.           Inc(I);
  26.           Dec(Span);
  27.         end
  28.         else
  29.           Break;
  30.       until Span = 0;
  31.       Strings[J] := S1;
  32.       if Span > 0 then {there's a conflict, adjust ColSpan to a practical value}
  33.         CellObj.ColSpan := CellObj.ColSpan - Span;
  34.     end;
  35. end;
  36.  

Corrected by:

Code: Pascal  [Select][+][-]
  1.  
  2. My changes applied:
  3.  
  4. procedure TCellManager.AddCell(Row: Integer; CellObj: TCellObj);
  5. {Adds this cell to the specified row}
  6. var
  7.   I, J, K, Span: Integer;
  8.   S1: ThtString;
  9. begin
  10. {make sure there's enough rows to handle any RowSpan for this cell}
  11.   while Count < Row + CellObj.RowSpan do
  12.     Add(StringOfChar('o', Table.ColSpecs.Count));
  13.   I := Pos('o', Strings[Row]); {where we want to enter this cell}
  14.   K := I;
  15.   if I > 0 then {else it's beyond the ColInfo and we're not interested}
  16.     for J := Row to Row + CellObj.RowSpan - 1 do {do for all rows effected}
  17.     begin
  18.       I := K;
  19.       Span := CellObj.ColSpan; {need this many columns for this cell}
  20.       S1 := Strings[J];
  21.       repeat
  22.         if I > Length(S1) then   // This line added by Kevin Morris 2019-Mar-03
  23.           Dec(I);                // This line added by Kevin Morris 2019-Mar-03
  24.         if S1[I] = 'o' then
  25.           begin
  26.             S1[I] := 'x';
  27.             Inc(I);
  28.             Dec(Span);
  29.         end
  30.           else
  31.             Break;
  32.       until Span = 0;
  33.       Strings[J] := S1;
  34.       if Span > 0 then {there's a conflict, adjust ColSpan to a practical value}
  35.         CellObj.ColSpan := CellObj.ColSpan - Span;
  36.     end;
  37. end;
  38.  
  39.  
 
Error goes away, but not sure if this is the best solution.

 

TinyPortal © 2005-2018