#1 2016-10-05 16:45:29

jars
Member
Registered: 2015-05-15
Posts: 29

Help with serialization a record with set of enumerated

Hi,
I'm developing with Delphi 7 and I don't known how define the constant for this record. Can you help me?

type
  TPosFlag = (pfInService, pfSupervisorHelp, pfReadyForCalls, pfMakingCall,
    pfMakingCall2, pfReadyForChats, pfACDCall, pfACDChat, pfEnteringDigits);

  TPosData = packed record
    PosNumber: Word;                 
    UserId: Word;                    
    PosFlags: set of TPosFlag;
  end;

const
  __TPosData = 'PosNumber Word UserId Word PosFlags set of TPosFlag';

Thanks in advance.

Offline

#2 2016-10-05 17:04:05

turrican
Member
From: Barcelona
Registered: 2015-06-05
Posts: 94
Website

Re: Help with serialization a record with set of enumerated

What do you want?

- Declare a constant for this record :

  TPosData = packed record
    PosNumber: Word;                 
    UserId: Word;                    
    PosFlags: set of TPosFlag;
  end;

const
  POSTDATA : TPosData = (PosNumber : 10; UserID : 11; PosFlags : [pfInService]);

Offline

#3 2016-10-05 18:43:13

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Help with serialization a record with set of enumerated

Hi Turrican.
I want pass to JSon.

    TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TPosData),
  __TPosData).Options := [soReadIgnoreUnknownFields,soWriteHumanReadable];

Offline

#4 2016-10-05 19:25:51

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

Re: Help with serialization a record with set of enumerated

Define a specific type like

TPosFlags = set of TPosFlag;

Then register this simple type, and the __TPostData text, using "PosFlags: TPosFlags".

Offline

#5 2016-10-05 20:11:28

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Help with serialization a record with set of enumerated

Thanks Ab.
With this code fire the error: TJSONCustomParsers.Search(kind=6) not DynArray or Record.

type
  TPosFlags = set of TPosFlag;
const
  __TPosFlags = '(pfInService, pfSupervisorHelp, pfReadyForCalls, pfMakingCall, '+
                'pfMakingCall2, pfReadyForChats, pfACDCall, pfACDChat, pfEnteringDigits)';

type
  TPosData = packed record
    PosNumber: Word;
    UserId: Word;
    PosFlags: TPosFlags;
  end;
  TACDPositions = array of TPosData;
const
  __TPosData = 'PosNumber Word UserId Word PosFlags TPosFlag'
               

    TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TPosFlags),
 __TPosFlags).Options := [soReadIgnoreUnknownFields,soWriteHumanReadable];

Offline

#6 2016-10-05 21:02:22

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

Re: Help with serialization a record with set of enumerated

Use this method:

TTextWriter.RegisterCustomJSONSerializerFromTextSimpleType(TypeInfo(TPosFlags));

Offline

#7 2016-10-06 13:24:30

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Help with serialization a record with set of enumerated

Many thanks AB, this work fine.

Offline

Board footer

Powered by FluxBB