• 客户端远程方法声明


    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;

  • 相关阅读:
    Javascript异步与同步问题
    promise解决异步问题:.then和async_await的渊源
    vue 爬坑之路----移动端适配rem单位
    vue 爬坑之路---can't resolve 'sass-loader'
    vue-cli新建vue项目
    sublimeT3编译sass.为css到指定的路径。
    禁止滚动条滚动
    让本地的静态html页面在node上跑起来
    地址三联动,简明实现
    关于数组去重
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3580446.html
Copyright © 2020-2023  润新知