views:

237

answers:

1

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;
A: 

Aren't you duplicating the way Datasnap calls the remote methods? Look for example "Calling server methods using TSQLServerMethod component"

ldsandon
I don't see where is the duplication, please read my first comment on the original post, as reply for Nick Hodges.
Alin Sfetcu
http://edn.embarcadero.com/print/38682#4CallingservermethodsusingTSQLServerMethodcomponent
ldsandon