#1 2023-07-30 13:51:44

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 58

Collections.newKeyValue<RawUtf8,variant>() prompting syntax errors

FPC 3.2.2  lazarus2.2.6

Use the class IkeyValue in mormot.core.collections

The following code keeps getting errors:  Fatal: Syntax error, ";" expected but "," found.

  vparams:specialize IkeyValue<RawUtf8,variant>;

  vParams:=Collections.NewPlainKeyValue<RawUtf8, variant>();    //There are errors in this line

Offline

#2 2023-07-30 16:47:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,244
Website

Re: Collections.newKeyValue<RawUtf8,variant>() prompting syntax errors

I never use the FPC syntax for generics.
Try to enable the Delphi mode for the unit instead.
Then use the Delphi syntax for generics: it is more readable, and works.

My wild guess is that your syntax is not correct.
Please try something like

vParams:=Collections.specialize NewPlainKeyValue<RawUtf8, variant>();

As I wrote, FPC syntax is so much verbose...

Offline

#3 2023-07-31 13:15:47

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 58

Re: Collections.newKeyValue<RawUtf8,variant>() prompting syntax errors

Thank you. Yes, you're right. It's up and running.

I want to sort the elements of IKeyValue by Key, and I don't know any good way to do that.

Offline

#4 2023-07-31 14:13:22

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Collections.newKeyValue<RawUtf8,variant>() prompting syntax errors

lfyey121 wrote:

I want to sort the elements of IKeyValue by Key, and I don't know any good way to do that.

IKeyValue is a replacement for TDictionary to search and get fast a Value instance. I do not think you should use it if you want to have a list of instances sorted.

If you want a list of instances you can sort in multiple ways you can use ilist<> and assigned a compare method

Last edited by dcoun (2023-07-31 17:22:49)

Offline

Board footer

Powered by FluxBB