I want to create a service function that returns a list of an entity.
The entity is unknown for development purposes. It is only passed as a parameter.
Is something like that possible?
I already have a general function internally that returns a list. I just need to make the call typeless
See the last/bottom function
function TReportFunc.list( const Param: TJSONObject): TList;
//*************************************************************************************
//*************************************************************************************
type
[ServiceContract]
[URIPathSegment('sf')]
{$I 'sngModellist.inc'}
IsngFunc = interface(IInvokable)
['{9615BB0F-66A5-4B60-B854-E5098443B6BD}']
function RegisterService : TJSONObject;
function RegisterDefaultSettings : TJSONObject;
function InstallDB : TJSONObject;
function UpdateDB ( const Param: TJSONObject) : TJSONObject;
function Uninstall ( const Param: TJSONObject) : TJSONObject;
function Backup ( const Param: TJSONObject) : TJSONObject;
function Restore ( const Param: TJSONObject) : TJSONObject;
[HttpGet] function Version : TJSONObject;
[HttpGet] function DBVersion : TJSONObject;
function Callback ( const CallbackFunction: string; const Param: TJSONObject): TJSONObject;
function CloseModule ( const Param: TJSONObject) : TJSONObject;
function Signal ( const Param: TJSONObject) : TJSONObject;
function GetSetting_list ( const Param: TJSONObject) : TList<TsngDBSettings>;
function GetSetting ( const Param: TJSONObject) : TJSONObject;
function SetSetting ( const Param: TJSONObject) : TJSONObject;
function GetLookupDic : TStream;
[HttpGet] function temp ( const Filename: String) : TStream;
//################################################# <--- This is, what I want
function list ( const Param: TJSONObject) : TList; // TList<unknown type>
//#################################################
end;
//*************************************************************************************
//*************************************************************************************
type
[ServiceContract]
[URIPathSegment('func')]
[Model('sngReport')]
IReportFunc = interface(IInvokable)
['{DEC46D08-9170-4EE2-B240-6C7C80B160C5}']
function generate ( const Param: TJSONObject) : TStream;
function preparedesign ( const Param: TJSONObject) : TJSONObject;
function ExampleList ( const Param: TJSONObject) : TList<TExampleEntity>;
end;
//*************************************************************************************
//*************************************************************************************
type
[ServiceImplementation]
TReportFunc = class(TInterfacedObject, IsngFunc, IReportFunc)
strict private // Interface IsngFunc
function RegisterService : TJSONObject;
function RegisterDefaultSettings : TJSONObject;
function InstallDB : TJSONObject;
function UpdateDB ( const Param: TJSONObject) : TJSONObject;
function Uninstall ( const Param: TJSONObject) : TJSONObject;
function Backup ( const Param: TJSONObject) : TJSONObject;
function Restore ( const Param: TJSONObject) : TJSONObject;
function Version : TJSONObject;
function DBVersion : TJSONObject;
function Callback ( const CallbackFunction: string; const Param: TJSONObject): TJSONObject;
function CloseModule ( const Param: TJSONObject) : TJSONObject;
function Signal ( const Param: TJSONObject) : TJSONObject;
function GetSetting_list ( const Param: TJSONObject) : TList<TsngDBSettings>;
function GetSetting ( const Param: TJSONObject) : TJSONObject;
function SetSetting ( const Param: TJSONObject) : TJSONObject;
function GetLookupDic : TStream;
function temp ( const Filename: String) : TStream;
//################################################# <--- This is, what I want
function list ( const Param: TJSONObject) : TList; // TList<unknown type>
//#################################################
strict private // Interface IReportFunc
function generate ( const Param: TJSONObject) : TStream;
function preparedesign ( const Param: TJSONObject) : TJSONObject;
function ExampleList ( const Param: TJSONObject) : TList<TExampleEntity>;
end;
//*************************************************************************************
class function EntityList_list<T: class> ( const Param: TJSONObject) : TList<T>;
var
LCriteria : TCriteria<T>;
begin
... code ...
LCriteria := TdmDatabase.JSONFilterToAureliusCriteria<T>( Tenant, Branch, LsngPara.JSONData);
if LsngPara.PageSize > 0 then
LCriteria.Skip( LsngPara.PageIndex * LsngPara.PageSize).Take( LsngPara.PageSize);
Result := LCriteria.List;
... code ...
end;
//*************************************************************************************
function TReportFunc.ExampleList( const Param: TJSONObject): TList<TExampleEntity>;
begin
Result := TsngFunc.EntityList_list<TExampleEntity>( Param);
end;
//*************************************************************************************
function TReportFunc.list( const Param: TJSONObject): TList;
begin
Find class from Param string
call TsngFunc.EntityList_list<class>( Param)
make result as in TList<MyClass>
Result :=
end;