I'm new to fpc Lazarus and came from Delphi BackGround.
I need to create a method in order to convert Generic Object Lists into TJsonArray.
Delphi has it natively, but aparently FPC Lazarus doesn't.
Here is what I have:
generic class function TDAOJsonUtils.ObjectListToJsonArray<T>(aObjectList: T): TJsonArray;
var
I: Integer;
_JsonStr: TJSONStreamer;
_JsonObj: TJsonObject;
begin
result := TJsonArray.Create;
_JsonStr := TJSONStreamer.Create(nil);
try
for i := 0 to Pred(TFPGObjectList(aObjectList).Count) do
begin
_JsonObj := TJsonObject.Create;
end;
finally
FreeAndNil(_JsonStr);
end;
end;
It doesn't compile with and throw the following message at the "for loop" statement:
"generics without specialization cannot be used as a type for a variable"
Any tips?
Thank's in advance.