修改 cxFilter 使之支持Oracle的日期型。
在DataControler 里有一份文件 cxFilter.pas,此文件定义了在 cxgrid 中进行 Filter 时的一些动作,此次正好我要用到,于是看了一下,发现其中的日期型有点问题。
在第863 行附近改成如下:
1
function TcxFilterOperator.GetExpressionValue(const AValue: Variant): string;
2
var
3
AVarType: Integer;
4
begin
5
if not PrepareExpressionValue(AValue, Result) then
6
begin
7
AVarType := VarType(AValue);
8
if (AVarType = varString) or (AVarType = varOleStr) then // <- VarTypeIsStr()
9
Result := QuotedStr(VarToStr(AValue))
10
else
11
if AVarType = varDate then
12
begin
13
// DateTimeFormat:='YYYY-MM-DD'; //临时定义日期格式
14
Result:=' TO_DATE('+QuotedStr( CriteriaItem.Criteria.ConvertDateToStr(
15
AValue))+','+Quotedstr('YYYY-MM-DD')+')';
16
end
17
// 原来的日期没有加 to_date ,Oracle 不认。
18
// Result := '''' + CriteriaItem.Criteria.ConvertDateToStr(AValue) + ''''
19
else
20
if AVarType = varBoolean then
21
Result := CriteriaItem.Criteria.ConvertBoolToStr(AValue)
22
else
23
if AVarType = varNull then
24
Result := 'NULL'
25
else
26
Result := VarToStr(AValue);
27
CriteriaItem.Criteria.FormatFilterTextValue(CriteriaItem, AValue, Result);
28
end;
29
end;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
于是,这个世界清静了,不过,这个日期定义太死了,没有时间。而实际上在使用时我一般都不带时间的,所以总觉得不完美,应该在外面定义的时候把这个 format 定义出来,这样比较好。
还有一处,cxFilter 在处理 为空和不为空的时候出现这种 = NULL 和 <> NULL ,而Oracle是不接受这种的,要改成 Is NULL 和 Is Not Null 。