#1 2024-09-08 19:10:25

kadaif
Member
Registered: 2022-03-27
Posts: 2

JSON array/list and TSQLRecord

I have a class derived from TSQLRecord, with several string fields.
I want to save the list/array of instances in one json file. Should I use array or TObjectList, and how to save and load? Eventually, convert that list into a dataset (with JSONToDataSet?).

Offline

#2 2024-09-09 05:57:31

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

Re: JSON array/list and TSQLRecord

Both works well.
For loading, you need to supply the TSQLRecord class type you are using, or the TSQLRecordDynArray for an array.

Of course the classical/regular Delphi way is to use a collection.

Usually, I prefer dynamic arrays.
No need to specify the type when you retrieve an item.
And you have plenty of ObjArray*() functions to manage them.
Do not forget to call ObjArrayClear() in a finally ObjArrayClear(arr); end; clause to actually release the TSQLRecord instances.

If you which to mORMot 2, you would have mORMot collections, which are even easier to use.

Offline

Board footer

Powered by FluxBB