Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Problems compiling a unit using TComparer



Permlink Replies: 1 - Last Post: Jul 27, 2017 6:45 AM Last Post By: Debbie Erickson
Debbie Erickson

Posts: 12
Registered: 4/4/13
Problems compiling a unit using TComparer
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 27, 2017 6:33 AM
Good morning, all. I am using D10 on a Windows 10 computer. I have a TObjectList I created. So I included System.Generics.Collections in the uses of the interface section. So far, so good. It compiled.

I want to define my own sort for the objectlist. The sort clause is
fgroupListFieldsList.Sort(*TComparer*<TGroupListFields>.Construct(
function (const L, R: TGroupListFields): integer
begin
if L.SequenceOrder=R.SequenceOrder then
Result:=0
else
if L.SequenceOrder< R.SequenceOrder then
Result:=-1
else
Result:=1;
end
));

The compiler couldn't find the TComparer class. I see that this class is defined in system.generics.default. So I tried to add that unit to my uses clause in the interface. What units do I need to be able to compile? Does the order of the units matter? I know it never used to in Delphi, but I'm a novice at using C#-like Delphi.

Seeing anonymous methods used in Delphi is pretty wild to me. Been using Delphi for about 25 yrs and didn't expect to see the language features merge like this. LOL!

Thanks!
Debbie Erickson

Posts: 12
Registered: 4/4/13
Re: Problems compiling a unit using TComparer
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 27, 2017 6:45 AM   in response to: Debbie Erickson in response to: Debbie Erickson
Please ignore this post! I forgot the "s" at the end of default. So stupid! Typo!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02