DataSnap 2010 中的通用请求函数?
这是我正在尝试构建的一个更通用的客户端函数,它允许我调用返回 TDBXReader 的不同服务器端过程。现在它有效,但我面临几个问题,我需要你的帮助:(
- 最重要)你对这种方法有何看法?有什么建议/建议吗?
- 我如何释放 vLClient(实际上是 TSrvMethodClient)?
- 为什么我不允许将第二个参数传递给 Create 方法?
谢谢。
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不是在重复 Datasnap 调用远程方法的方式吗?查找示例“使用 TSQLServerMethod 组件调用服务器方法”
Aren't you duplicating the way Datasnap calls the remote methods? Look for example "Calling server methods using TSQLServerMethod component"