* add NULL handling for customvariants, patch by Ludo, Mantis #20697

git-svn-id: trunk@19660 -
This commit is contained in:
marco 2011-11-20 19:45:22 +00:00
parent a52fe3162d
commit b070a0bbbc

View File

@ -1238,37 +1238,61 @@ function DoVarCmpComplex(const Left, Right: TVarData; const OpCode: TVarOp): Sho
var Handler: TCustomVariantType; var Handler: TCustomVariantType;
CmpRes: boolean; CmpRes: boolean;
begin begin
if FindCustomVariantType(Left.vType, Handler) then if (Left.vType=varnull) or (Right.vType=varnull) then
CmpRes := Handler.CompareOp(Left, Right, OpCode) // don't bother custom variant handlers with conversion to NULL
else if FindCustomVariantType(Right.vType, Handler) then begin
CmpRes := Handler.CompareOp(Left, Right, OpCode) if OpCode in [opCmpEq,opCmpNe] then
begin
if (Left.vType=Right.vType) xor (OpCode=opCmpNe) then
result:=0
else
result:=-1;
end
else
if Left.vType=varnull then
begin
if Right.vType=varnull then
Result := 0
else
Result := -1;
end
else
Result := 1;
end
else else
VarInvalidOp(Left.vType, Right.vType, OpCode); begin
if FindCustomVariantType(Left.vType, Handler) then
CmpRes := Handler.CompareOp(Left, Right, OpCode)
else if FindCustomVariantType(Right.vType, Handler) then
CmpRes := Handler.CompareOp(Left, Right, OpCode)
else
VarInvalidOp(Left.vType, Right.vType, OpCode);
case OpCode of case OpCode of
opCmpEq: opCmpEq:
if CmpRes then if CmpRes then
Result:=0 Result:=0
else else
Result:=1; Result:=1;
opCmpNe: opCmpNe:
if CmpRes then if CmpRes then
Result:=1 Result:=1
else else
Result:=0; Result:=0;
opCmpLt, opCmpLt,
opCmpLe: opCmpLe:
if CmpRes then if CmpRes then
Result:=-1 Result:=-1
else else
Result:=1; Result:=1;
opCmpGt, opCmpGt,
opCmpGe: opCmpGe:
if CmpRes then if CmpRes then
Result:=1 Result:=1
else else
Result:=-1; Result:=-1;
end; end;
end;
end; end;