DataSnap 2010 中的通用请求函数?

发布于 2024-08-14 20:08:28 字数 1388 浏览 7 评论 0原文

这是我正在尝试构建的一个更通用的客户端函数,它允许我调用返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肥爪爪 2024-08-21 20:08:28

您不是在重复 Datasnap 调用远程方法的方式吗?查找示例“使用 TSQLServerMethod 组件调用服务器方法”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文