diff --git a/components/fpspreadsheet/source/common/fpsreaderwriter.pas b/components/fpspreadsheet/source/common/fpsreaderwriter.pas index 04d0eb3e4..318c08568 100644 --- a/components/fpspreadsheet/source/common/fpsreaderwriter.pas +++ b/components/fpspreadsheet/source/common/fpsreaderwriter.pas @@ -1199,7 +1199,8 @@ begin begin // Bring the priority format to the top idx := IndexOf(APriorityFormat); - FList.Exchange(0, idx); + if idx > -1 then + FList.Exchange(0, idx); end; SetLength(Result, FList.Count); @@ -1224,7 +1225,8 @@ begin if APriorityFormat <> sfidUnknown then // Restore original order - FList.Exchange(idx, 0); + if idx > -1 then + FList.Exchange(idx, 0); end; function TsSpreadFormatRegistry.GetFormatName(AFormatID: TsSpreadFormatID): String;