#1 2019-11-27 11:59:37

tbo
Member
Registered: 2015-04-20
Posts: 353

Generics versions of RetrieveListObjArray

Hallo!

I'm just taking my first steps with generics (Delphi XE). My question: Can generic versions
of RetrieveListObjArray be included?

function TSQLRest.RetrieveListObjArray<T>(const aCustomFieldsCSV: RawUTF8): TArray<T>;
function TSQLRest.RetrieveListObjArray<T>(const FormatSQLWhere: RawUTF8;
  const BoundsSQLWhere: array of const; const aCustomFieldsCSV: RawUTF8): TArray<T>;

With best regards
Thomas

Offline

#2 2019-11-27 17:02:40

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

Re: Generics versions of RetrieveListObjArray

I am not sure that TArray<T> will completely work as expected with the serialization/registration mechanism.

For instance, I doubt that TypeInfo(TArray<TMyObject>) would match TypeInfo(TMyObjectObjArray) with TMyObjectObjArray = array of TMyObject as we expect...

Offline

#3 2019-11-27 18:29:45

tbo
Member
Registered: 2015-04-20
Posts: 353

Re: Generics versions of RetrieveListObjArray

Hallo!

Sorry, I'm no help at generics. I started testing with Spring4D.
The following works for me.

type
  TSQLMyObject = class(TSQLCustomRecord)
  ...
  end;
 
  TSQLMyObjectList = class(Spring.Collections.Lists.TObjectList<TSQLMyObject>);

FDataList: Spring.Collections.IList<TSQLMyObject>;
 
procedure LoadMyObjects;
var
  tmpArr: TArray<TSQLMyObject>;
begin
  Client.RetrieveListObjArray(tmpArr, TSQLMyObject, 'ObjectID = ?', [0]);
  FDataList := TSQLMyObjectList.Create(tmpArr);
  ...
end; 

With best regards

Offline

#4 2019-11-27 19:04:46

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

Re: Generics versions of RetrieveListObjArray

Dont forget to release the array items otherwise you will leak memory!

Offline

Board footer

Powered by FluxBB