This is a client-side function i'm trying to build, more generalized, which will allow me to call different server-side procedures which return TDBXReader. Right now it works, BUT i'm facing couple of problems and i need your help:
- (most important) what do you think about this aproach ? any suggestions/advices ?
- how can i free the vLClient (which in fact is a TSrvMethodClient) ?
- why i'm not allowed to pass a 2nd argument to the Create method ?
Thank you.
function askServerTo_give(SQLConn: TSQLConnection; procName: String; cds: TClientDataSet): Boolean;
var
ctx : TRttiContext;
SrvRTTI: TRttiType;
vLClient, vLReader: TValue;
//LClient : TSrvMethodsClient;
begin
Result := False;
vLClient := nil;
vLReader := nil;
ctx := TRttiContext.Create;
SrvRTTI := ctx.GetType(TSrvMethodsClient.ClassInfo);
vLClient := SrvRTTI.GetMethod('Create').Invoke(SrvRTTI.AsInstance.MetaclassType, [ SQLConn.DBXConnection ] );
//vLClient := SrvRTTI.GetMethod('Create').Invoke(SrvRTTI.AsInstance.MetaclassType, [ SQLConn.DBXConnection , False] ); // Error!
//LClient := TSrvMethodsClient.Create( SQLConn.DBXConnection, False);
try
vLReader := SrvRTTI.GetMethod( procName ).Invoke(vLClient, []);
if (vLReader.AsObject as TDBXReader) <> nil then begin
TDBXDataSetReader.CopyReaderToClientDataSet((vLReader.AsObject as TDBXReader), cds);
Result := not cds.IsEmpty;
end;
finally
(vLReader.AsObject as TDBXReader).Free; //FreeAndNil() doesn`t work
//(vLClient.AsObject as TSrvMethodsClient).Free; // Error!
ctx.Free;
end;
end;