zoukankan      html  css  js  c++  java
  • 客户端远程方法声明

    datasnap多层框架在客户端要生成调用远程方法的接口,一个可以鼠标右键点选sqlconnection控件,然后选“generate datasnap client...”,就会自动生成一个所有远程方法的接口单元,这种方法完全不需要我们自己来写代码,超级省事。但也有不好的地方,一个是首先sqlconnection必需要连接上中间件(设置好一些属性后,静态连接),二个是凡中间件有的远程方法一股脑都给你生成了(都让人给看见了)。下面的方法通过自己写代码来声明远程方法调用,避免了前面的两点不足,缺点当然是要自己写代码了。

    function TRemoteMethods.GetSearchSQLData(const sSQLStr: string;
    clientdataset: TClientDataSet; dbType: Integer = 0): Boolean;
    var
    v: OleVariant;
    begin
    Result := False;
    if (sSQLStr = '') or (not Assigned(clientdataset)) then
    Exit;
    SQLConnection1.Connected := False;
    try
    try
    SQLConnection1.Connected := True;
    except
    on E: Exception do
    begin
    SysLog.WriteLog('TRemoteMethods.GetSearchSQLData' + E.Message);
    Exit;
    end;
    end;
    // 执行
    SqlServerMethod1.Close;
    SqlServerMethod1.SQLConnection := nil;
    SqlServerMethod1.ServerMethodName := '';
    SqlServerMethod1.SQLConnection := SQLConnection1;
    SqlServerMethod1.ServerMethodName := 'TSysMethods.GetSearchSQLData';
    try
    SqlServerMethod1.ParamByName('SQLStr').AsString := sSQLStr;
    SqlServerMethod1.ParamByName('DBType').AsInteger := dbType;
    SqlServerMethod1.ExecuteMethod;
    v := Null;
    if SqlServerMethod1.ParamByName('ReturnParameter').AsBoolean then
    v := SqlServerMethod1.ParamByName('OV').Value;
    if not VarIsNull(v) then
    begin
    clientdataset.Data := v;
    Result := True;
    end;
    except
    on E: Exception do
    begin
    SysLog.WriteLog('TRemoteMethods.GetSearchSQLData' + E.Message);
    end;
    end;
    finally
    SqlServerMethod1.Close;
    SqlServerMethod1.SQLConnection := nil;
    SqlServerMethod1.ServerMethodName := '';
    SQLConnection1.Connected := False;
    end;
    end;

  • 相关阅读:
    OCP-1Z0-051-V9.02-162题
    OCP-1Z0-051-V9.02-161题
    OCP-1Z0-051-V9.02-160题
    Matlab中矩阵的分解
    OCP-1Z0-051-V9.02-158题
    OCP-1Z0-051-V9.02-157题
    Matlab中特殊的矩阵函数
    求Matlab中矩阵的秩和迹
    Matlab中的条件数
    在android里使用boost c++
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3580446.html
Copyright © 2011-2022 走看看