cds.data:=dsp.data赋值有时会出现AV错误剖析

cds.data:=dsp.data赋值有时会出现AV错误剖析

 

如果QUERY没有查询到任何数据,cds.data:=dsp.data赋值会触发AV错误。

大家知道,DATASNAP有许多远程方法就是返回OLEVARIANT类型的数据,当远程方法没有返回任何数据的时候,cds.data:=远程方法函数赋值的时候,同样会触发AV错误。

那么怎样解决此类问题呢?

1)中间件远程方法作如下处理

function TServerMethods1.QuerySql(const accountNo, sql: WideString): OleVariant;
var
d: TfrmDB;
begin
Result := null;  // 默认返回NULL
if (accountNo = '') or (sql = '') then
Exit;

2)客户端调用远程方法作如下处理

function TdmSys.QuerySQL(const sql: string; cds: TClientDataSet; accountno: string = '0'): Boolean;
var
v: OleVariant;
m: TServerMethods1Client;
begin
Result := False;
try
waitInfo.Show;
waitInfo.Update;

if appInfo.tier = 3 then
begin
if ConnectAppServer and (sql <> '') and (cds <> nil) then
begin
m := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
v := m.QuerySQL(accountno, sql);
m.Free;
if not VarIsNull(v) then  // VarIsNull(v) 判断远程方法是否有返回数据
begin
cds.Data := v;
Result := True;
end;
end;

posted @ 2016-09-20 09:12  delphi中间件  阅读(936)  评论(0编辑  收藏  举报