Use a collection or a TObjectList.
Or a dynamic array of records, with custom JSON serialization.
See the SAD 1.18 pdf for further note.
See also latest sample 20, in the source code repository.
]]>{$M+}
type
TDataType = (tlTemperature, tlHumidity);
TData = class
private
FPortId : Integer;
FDataType: TDataType;
FValue : Double;
function Get_PortId: Integer;
function Get_DataType: TDataType;
function Get_Value: Double;
procedure Set_PortId(const Value: Integer);
procedure Set_DataType(const Value: TDataType);
procedure Set_Value(const Value: Double);
published
property PortId : Integer read Get_PortId write Set_PortId;
property DataType: TDataType read Get_DataType write Set_DataType;
property Value : Double read Get_Value write Set_Value;
end;
TDataList = class (TList<TData>)
end;
TDataArray = Array of TData;
TAcquisitionBoard = class
private
FIdentify: RawUTF8;
FModel : RawUTF8;
FData : TDataArray;
function Get_Identify: RawUTF8;
function Get_Model: RawUTF8;
function Get_Data: TDataArray;
procedure Set_Identify(const Value: RawUTF8);
procedure Set_Model(const Value: RawUTF8);
public
constructor Create;
destructor Destroy; override;
function AddData: TData;
published
property Identify: RawUTF8 read Get_Identify write Set_Identify;
property Model : RawUTF8 read Get_Model write Set_Model;
property Data : TDataArray read Get_Data;
end;
Whereas the objects have the following data:
Identify: 12345 Model: A2013
Temperature: 23.79
Temperature: 30.02
When running memoJSON.Lines.Text: = UTF8ToString (ObjectToJSON (FAcquisitionBoard, []));
I get: {"Identify": "12345", "Model": "A2013", "Data": []}
Without informing the content of the property "Data".
How to get complete information? Data as Dynamic Array or TObjectList<> or other structure...
Thanks in advance!
]]>