Recent

Author Topic: TsSearchEngine.Matches() error raised on empty cells with FPC V3.2.0  (Read 881 times)

russeld

  • New Member
  • *
  • Posts: 17
Hi,

With FPC V3.0.4 a worksheet could be searched without problems using regular expressions. Function TRegExpr.ExecPrim() in unit RegExpr.pas used to throw an 'empty input string' error if the string wasn't assigned, however with changes to package regexpr in V3.2.0, the error is raised if the string is empty. As most cells in a worksheet are empty, it is inevitable that this error is raised.

A check in TsSearchEngine.Matches() fixes this problem.

Code: Pascal  [Select][+][-]
  1. function TsSearchEngine.Matches(AWorksheet: TsWorksheet; ARow, ACol: Cardinal): Boolean;
  2. var
  3.   cell: PCell;
  4.   txt: String;
  5. begin
  6.   cell := AWorksheet.FindCell(ARow, ACol);
  7.   txt := '';
  8.   if cell <> nil then
  9.   begin
  10.     if (soSearchInComment in FSearchParams.Options) then
  11.       txt := AWorksheet.ReadComment(cell)
  12.     else
  13.       txt := AWorksheet.ReadAsText(cell);
  14.   end;
  15.  
  16.   //--- Check added for empty string
  17.   if txt.IsEmpty then
  18.     exit(false);
  19.   //---
  20.  
  21.   if soRegularExpr in FSearchParams.Options then
  22.     Result := FRegEx.Exec(txt)
  23.   else
  24.   begin
  25.     if not (soMatchCase in FSearchParams.Options) then
  26.       txt := UTF8Lowercase(txt);
  27.     if soCompareEntireCell in FSearchParams.Options then
  28.       exit(txt = FSearchText);
  29.     if pos(FSearchText, txt) > 0 then
  30.       exit(true);
  31.     Result := false;
  32.   end;
  33. end;
  34.  

Bart

  • Hero Member
  • *****
  • Posts: 4516
    • Bart en Mariska's Webstek
Re: TsSearchEngine.Matches() error raised on empty cells with FPC V3.2.0
« Reply #1 on: April 07, 2021, 01:28:47 pm »
IIRC then this is fixed in 3.2.2 ("soon" to be released).

Bart

wp

  • Hero Member
  • *****
  • Posts: 9048
Re: TsSearchEngine.Matches() error raised on empty cells with FPC V3.2.0
« Reply #2 on: April 09, 2021, 10:15:36 pm »
Applied the fix in fpspreadsheet trunk. Thank you.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018