我在DBConsts中找到这个错误了SExprBadScope = 'Operation cannot mix aggregate value with record-varying value',然后搜索了找到了代码行:procedure TExprParser.GetScopeKind(Root, Left, Right : PExprNode); begin if (Left = nil) and (Right = nil) then Exit; if Right = nil then begin Root.FScopeKind := Left.FScopeKind; Exit; end; if ((Left^.FScopeKind = skField) and (Right^.FScopeKind = skAgg)) or ((Left^.FScopeKind = skAgg) and (Right^.FScopeKind = skField)) then DatabaseError(SExprBadScope); if (Left^.FScopeKind = skConst) and (Right^.FScopeKind = skConst) then Root^.FScopeKind := skConst else if (Left^.FScopeKind = skAgg) or (Right^.FScopeKind = skAgg) then Root^.FScopeKind := skAgg else if (Left^.FScopeKind = skField) or (Right^.FScopeKind = skField) then Root^.FScopeKind := skField; end;希望对你有用。
我也跟踪过,就是跟踪TCustomClientDataSet的Open过程要执行哪些动作,跟到后面跟丢了,因为执行的动作太多,也不在同一个Unit里,倒过去跟TExprParser更不可能,太多地方用,头都大了,最后放弃跟踪执行Open过程要执行的动作了。因为在做试验的时候偶然把问题解决掉了,运气比较好哈,呵呵,但不知道原因是什么,贴出来请大家分析下,明天结帖 var ProduceOP:String; begin ...... ProduceOP:=GetProduceOP;//GetProduceOP是一个获取字符串的函数,得到的是类似''123'',''234'',''345''的字符串 CDS_Produce.Filtered:=False; CDS_Produce.Filter:='OP_Code in('+ProduceOP+') and Flag=''Begin'''; CDS_Produce.Filtered:=True; CDS_Produce.Open; ..... end; 这样就不会不定时跳那错出来,但是下面这种写法就会偶尔的,不定时的跳operation cannot mix aggregate value with record-varying value 这个错误, var ProduceOP:String; begin ...... ProduceOP:=GetProduceOP;//GetProduceOP是一个获取字符串的函数,得到的是类似''123'',''234'',''345''的字符串 CDS_Produce.Filtered:=False; CDS_Produce.Filter:='(Not OP_Code in('+ProduceOP+')) and Flag=''Begin'''; CDS_Produce.Filtered:=True; CDS_Produce.Open; ..... end; 本来想少写一个函数省点事情,但是没有省着。各位兄弟有什么看法?
一个是IN,CDS_Produce.Filter:='OP_Code in('+ProduceOP+') and Flag=''Begin'''; 一个是NOT,CDS_Produce.Filter:='(Not OP_Code in('+ProduceOP+')) and Flag=''Begin''';逻辑对吗?
还有一个现象啊,虽然会报这个错,点掉继续用是没有任何问题的,并不影响系统的任何使用。
procedure DatabaseError(const Message: string; Component: TComponent = nil);
begin
if Assigned(Component) and (Component.Name <> '') then
raise EDatabaseError.Create(Format('%s: %s', [Component.Name, Message])) else
raise EDatabaseError.Create(Message);
end;
光标停留在raise EDatabaseError.Create(Message);这句
所以应该是raise EDatabaseError.Create(Format('%s: %s', [Component.Name, Message])) 这句出的operation cannot mix aggregate value with record-varying value 这个错误信息,但是没有错误信息里没有Component.Name呢???
客户端我都用的TClientDataSet,服务端用的TADOQuery+TDataSetProvider,设置TDataSetProvider的[poAllowCommandText]为True来执行客户端TClientDataSet提交的CommandText;
TADOTable+TDataSetProvider来给客户端的TClientDataSet直接访问表;我从初始用到聚合语句的模块到一个初始没用聚合语句但要打开表的模块时,偶尔就会出现这个错误,出了这个错想进的模块就不能动态生成了,要把错误点掉后在进模块就可以了
begin
if (Left = nil) and (Right = nil) then Exit;
if Right = nil then
begin
Root.FScopeKind := Left.FScopeKind;
Exit;
end;
if ((Left^.FScopeKind = skField) and (Right^.FScopeKind = skAgg))
or ((Left^.FScopeKind = skAgg) and (Right^.FScopeKind = skField)) then
DatabaseError(SExprBadScope);
if (Left^.FScopeKind = skConst) and (Right^.FScopeKind = skConst) then
Root^.FScopeKind := skConst
else if (Left^.FScopeKind = skAgg) or (Right^.FScopeKind = skAgg) then
Root^.FScopeKind := skAgg
else if (Left^.FScopeKind = skField) or (Right^.FScopeKind = skField) then
Root^.FScopeKind := skField;
end;希望对你有用。
var
ProduceOP:String;
begin
......
ProduceOP:=GetProduceOP;//GetProduceOP是一个获取字符串的函数,得到的是类似''123'',''234'',''345''的字符串
CDS_Produce.Filtered:=False;
CDS_Produce.Filter:='OP_Code in('+ProduceOP+') and Flag=''Begin''';
CDS_Produce.Filtered:=True;
CDS_Produce.Open;
.....
end;
这样就不会不定时跳那错出来,但是下面这种写法就会偶尔的,不定时的跳operation cannot mix aggregate value with record-varying value 这个错误,
var
ProduceOP:String;
begin
......
ProduceOP:=GetProduceOP;//GetProduceOP是一个获取字符串的函数,得到的是类似''123'',''234'',''345''的字符串
CDS_Produce.Filtered:=False;
CDS_Produce.Filter:='(Not OP_Code in('+ProduceOP+')) and Flag=''Begin''';
CDS_Produce.Filtered:=True;
CDS_Produce.Open;
.....
end;
本来想少写一个函数省点事情,但是没有省着。各位兄弟有什么看法?
TClientDataSet,对应着服务器端的TAdoQuery
一个是NOT,CDS_Produce.Filter:='(Not OP_Code in('+ProduceOP+')) and Flag=''Begin''';逻辑对吗?
我是偶然看到我另外一个模块进去打开表的过滤条件in条件前没有not,我就不停的进入那个模块,发现点了好几分钟,估计有好几百次,都没出那错误,而进入过滤条件in条件前有not的那个模块,基本上点个两分钟左右,过滤的结果虽然正确,但估计一百次左右的时候就会跳错。
我这笨人啊没办法就不停的点啊点来验证,
大家有什么看法吗?虽然幸运的解决了问题但是不知道原因总是有点遗憾啊
CDS_Produce 是TClientDataSet,对应着服务器端的TAdoTable;没有用CommandText;直接用的Filter 来设置的过滤条件,可能是过滤条件中的in条件前面不能有NOT。Filter还是比不得CommandText可以执行真正的Sql语句,估计TClientDataSet在使过滤条件起作用的时候出问题了(我猜测的),但是解释不了为什么有Not结果是正确的,只是会不知道哪一次打开的时候就会报错operation cannot mix aggregate value with record-varying value.
现在我要设置过滤条件:OP_Code in('123','234')
这个过滤条件与Not OP_Code in('345','456')这个过滤条件执行的结果是一样的,也是我想要的结果,但是用Not OP_Code in('345','456')这个过滤条件就会出现我提的问题。
CDS_Produce.Filter:='(Not OP_Code in('+ProduceOP+')) and Flag=''Begin'''; //换成OP_Code not in(....)试试
CDS_Produce.Filtered:=True;
CDS_Produce.Open;