View Issue Details

IDProjectCategoryView StatusLast Update
0035828FPCRTLpublic2019-07-11 14:56
Reporterrd0xAssigned To 
Status newResolutionopen 
Product Version3.2.0Product Build3.2.0-beta [2019/07/01] 
Target VersionFixed in Version 
Summary0035828: [generics.collections] Sort expects constref while Delphi wants const for parameters
DescriptionIf you create a TObjectList<MyClass> and call classvar.Sort(TComparer<MyClass>.Construct(_CompareNames)); you need to define the function _CompareNames (only way as FPC does not know anonymous functions) with 'constref' for FPC while Delphi needs 'const'

function _CompareNames(constref left, right: MyClass): Integer;

Delphi Rio:
function _CompareNames({const left, right: MyClass): Integer;

Additional InformationError: Incompatible type for arg no. 1: Got "_CompareNames(const MyClass;const MyClass):LongInt;", expected "<procedure variable type of function(constref MyClass;constref MyClass):LongInt;Register>"
Fixed in Revision
Attached Files


Sven Barth

2019-07-11 11:35

manager   ~0117178

I'll need to check whether we can add a overload that takes the Delphi compatible compare function. Cause constref can result in faster code due to it always passing a reference compared to const...


2019-07-11 14:56

reporter   ~0117181

I imagine Embarcadero *would* have used "const [ref]" had it existed in Delphi when they introduced Generics.Collections, FWIW.

Issue History

Date Modified Username Field Change
2019-07-11 08:46 rd0x New Issue
2019-07-11 08:47 rd0x Tag Attached: generics
2019-07-11 11:35 Sven Barth Note Added: 0117178
2019-07-11 14:56 Akira1364 Note Added: 0117181