From dfa57b80e92ded06965575a20de91df70f2dcdf5 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 20 May 2019 10:13:39 +0000 Subject: [PATCH] fpspreadsheet: Fix infinite loop in Worksheeet sorting when the sorted range contains an empty cell. Make Worksheetgrid.Sort public. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6928 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/source/common/fpspreadsheet.pas | 7 +++++++ .../fpspreadsheet/source/visual/fpspreadsheetgrid.pas | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/fpspreadsheet/source/common/fpspreadsheet.pas b/components/fpspreadsheet/source/common/fpspreadsheet.pas index 241307b34..584e9193c 100644 --- a/components/fpspreadsheet/source/common/fpspreadsheet.pas +++ b/components/fpspreadsheet/source/common/fpspreadsheet.pas @@ -4339,6 +4339,11 @@ begin if (ACell1 = nil) and (ACell2 = nil) then Result := 0 else + if (ACell1 <> nil) and (ACell1^.ContentType = cctEmpty) and + (ACell2 <> nil) and (ACell2^.ContentType = cctEmpty) + then + Result := 0 + else if (ACell1 = nil) or (ACell1^.ContentType = cctEmpty) then begin Result := +1; // Empty cells go to the end @@ -4349,9 +4354,11 @@ begin Result := -1; // Empty cells go to the end exit; // Avoid SortOrder to bring the empty cell to the top! end else + { if (ACell1^.ContentType = cctEmpty) and (ACell2^.ContentType = cctEmpty) then Result := 0 else + } if (ACell1^.ContentType = cctUTF8String) and (ACell2^.ContentType = cctUTF8String) then begin if ssoCaseInsensitive in ASortOptions then diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index ff66110ab..24a129a3a 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -324,7 +324,6 @@ type function SelectCell(ACol, ARow: Integer): Boolean; override; procedure SetEditText(ACol, ARow: Longint; const AValue: string); override; procedure Setup; - procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override; function ToPixels(AValue: Double): Integer; procedure TopLeftChanged; override; function TrimToCell(ACell: PCell): String; @@ -435,6 +434,8 @@ type const ALeftOuterStyle, ATopOuterStyle, ARightOuterStyle, ABottomOuterStyle, AHorInnerStyle, AVertInnerStyle: TsCellBorderStyle); + procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override; + { Row height / col width calculation } procedure UpdateColWidth(ACol: Integer); procedure UpdateColWidths(AStartIndex: Integer = 0); @@ -5569,6 +5570,7 @@ begin ); end; + {@@ ---------------------------------------------------------------------------- Converts a coordinate given in workbook units to pixels using the current screen resolution