这是我正在尝试构建的客户端功能,更通用,这将允许我调用返回TDBXReader的不同服务器端程序。现在它有效,但我面临几个问题,我需要你的帮助:
谢谢。
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;
答案 0 :(得分:1)
您是不是在复制Datasnap调用远程方法的方式?查看示例“使用TSQLServerMethod组件调用服务器方法”