Skip to content

Commit

Permalink
[expressions] fixed fpc compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Mar 14, 2020
1 parent 64d012c commit 8595cfd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Quick.Expression.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ TSingleExpression = class(TExpression)
fValue1 : string;
fOperator : TOperator;
fValue2 : string;
{$IFNDEF FPC}
function ListContains(aArrayObj : TObject; const aValue : string): Boolean;
function IListContains(aArrayObj : TValue; const aValue : string): Boolean;
{$ENDIF}
function ArrayContains(aArray : TValue; const aValue : string): Boolean;
public
property Value1 : string read fValue1 write fValue1;
Expand Down Expand Up @@ -274,14 +276,19 @@ function TSingleExpression.Validate(aValue : TObject) : Boolean;
TOperator.opLikeL : Result := StartsText(fValue2,value1);
TOperator.opContains :
begin
{$IFNDEF FPC}
if value1.IsObject then Result := ListContains(value1.AsObject,fValue2)
else if value1.IsInterface then Result := IListContains(value1.AsTValue,fValue2)
else if value1.IsArray then Result := ArrayContains(value1.AsTValue,fValue2);
{$ELSE}
if value1.IsArray then Result := ArrayContains(value1.AsTValue,fValue2);
{$ENDIF}
end
else raise ENotValidExpression.Create('Operator not defined');
end;
end;

{$IFNDEF FPC}
function TSingleExpression.ListContains(aArrayObj : TObject; const aValue : string): Boolean;
var
ctx : TRttiContext;
Expand Down Expand Up @@ -321,6 +328,7 @@ function TSingleExpression.IListContains(aArrayObj : TValue; const aValue : stri
raise EExpressionValidateError.Create('Interface property not supported');
end;
end;
{$ENDIF}

function TSingleExpression.ArrayContains(aArray : TValue; const aValue : string): Boolean;
var
Expand All @@ -335,7 +343,10 @@ function TSingleExpression.ArrayContains(aArray : TValue; const aValue : string)
Dec(count);
arrItem := aArray.GetArrayElement(count);
case arrItem.Kind of
tkString, tkUnicodeString, tkWideString : Result := CompareText(arrItem.AsString,aValue) = 0;
{$IFNDEF FPC}
tkString,
{$ENDIF}
tkUnicodeString, tkWideString : Result := CompareText(arrItem.AsString,aValue) = 0;
tkInteger, tkInt64 : Result := arrItem.AsInt64 = aValue.ToInt64;
tkFloat : Result := arrItem.AsExtended = aValue.ToExtended;
else raise EExpressionNotSupported.CreateFmt('Type Array<%s> not supported',[arrItem.TypeInfo.Name]);
Expand Down

0 comments on commit 8595cfd

Please sign in to comment.