From fe27d6ec34f2749ca2a6cc9fe7c912732b3ad470 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 17 Jul 2024 14:33:12 +0000 Subject: [PATCH] fpspreadsheet: Fix formula MATCH for match_type 1. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9388 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/source/common/fpsfunc.pas | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpsfunc.pas b/components/fpspreadsheet/source/common/fpsfunc.pas index cf38f6ece..1d6cb1294 100644 --- a/components/fpspreadsheet/source/common/fpsfunc.pas +++ b/components/fpspreadsheet/source/common/fpsfunc.pas @@ -2738,7 +2738,8 @@ procedure fpsMATCH(var Result: TsExpressionResult; value. The array can be sorted in any order.) match_type = -1: The MATCH function will find the smallest value that is greater than or equal to value. You should be sure to sort your array in - descending order. } + descending order. + Return value is the 1-based index in the array. } var match_type: Integer; searchString: String; @@ -2843,37 +2844,17 @@ begin if IsCol then begin - if match_type = -1 then - begin - for r := r2 downto r1 do - if Matches(sheet.FindCell(r, c1)) then begin - Result := IntegerResult(r - integer(r1) + 1); - exit; - end; - end else - begin - for r := r1 to r2 do - if Matches(sheet.FindCell(r, c1)) then begin - Result := IntegerResult(r - integer(r1) + 1); - exit; - end; - end; + for r := r2 downto r1 do + if Matches(sheet.FindCell(r, c1)) then begin + Result := IntegerResult(r - integer(r1) + 1); + exit; + end; end else begin - if match_type = -1 then - begin - for c := c2 downto c1 do - if Matches(sheet.FindCell(r1, c)) then begin - Result := IntegerResult(c - Integer(c1) + 1); - exit; - end; - end else - begin - for c := c1 to c2 do - if Matches(sheet.FindCell(r1, c)) then begin - Result := IntegerResult(c - Integer(c1) + 1); - exit; - end; + for c := c2 downto c1 do + if Matches(sheet.FindCell(r1, c)) then begin + Result := IntegerResult(c - Integer(c1) + 1); + exit; end; end;