⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ezbaseexpr.pas

📁 很管用的GIS控件
💻 PAS
📖 第 1 页 / 共 4 页
字号:
End;

Function TBetweenExpr.GetExprtype: TExprtype;
Begin
  Result := ttBoolean;
End;

{ TSQLInPredicateExpr - class implementation}

Constructor TSQLInPredicateExpr.Create( ParameterList: TParameterList; IsNotIn: Boolean );
Begin
  Inherited Create( ParameterList );
  FIsNotIn := IsNotIn;
End;

Function TSQLInPredicateExpr.GetAsBoolean: Boolean;
Var
  t: Integer;
  s: String;
  f: Double;
  i: Integer;
  b: Boolean;
Begin
  Result := False;
  { We'll compare expressions like
      COUNTRY IN ('USA','SPAIN','MEXICO','ENGLAND')
      CUSTID not IN (1,10,25)
      ISMARRIED IN (TRUE)
      Combination of parameters like:
      CUSTID IN ('USA', 2, 'MEXICO', 2.54)
      where CUSTID is integer, is invalid
  }
  Case Param[0].Exprtype Of
    ttString:
      Begin
        s := Param[0].AsString;
        For t := 1 To ParameterCount - 1 Do
          If s = Param[t].AsString Then
          Begin
            Result := True;
            Break;
          End;
      End;
    ttFloat:
      Begin
        f := Param[0].AsFloat;
        For t := 1 To ParameterCount - 1 Do
          If f = Param[t].AsFloat Then
          Begin
            Result := True;
            Break;
          End;
      End;
    ttInteger:
      Begin
        i := Param[0].AsInteger;
        For t := 1 To ParameterCount - 1 Do
          If i = Param[t].AsInteger Then
          Begin
            Result := True;
            Break;
          End;
      End;
    ttBoolean:
      Begin
        b := Param[0].AsBoolean;
        For t := 1 To ParameterCount - 1 Do
          If b = Param[t].AsBoolean Then
          Begin
            Result := True;
            Break;
          End;
      End;
  End;
  If FIsNotIn Then
    Result := Not Result;
End;

Function TSQLInPredicateExpr.GetExprtype: TExprtype;
Begin
  Result := ttBoolean;
End;

{ TCaseWhenElseExpr }

Constructor TCaseWhenElseExpr.Create( WhenParamList: TParameterList;
  ThenParamList: TParameterList; ElseExpr: TExpression );
Begin
  Inherited Create( WhenParamList );
  FThenParamList := ThenParamList;
  FElseExpr := ElseExpr;
End;

Procedure TCaseWhenElseExpr.CheckParameters;
Var
  I: Integer;
Begin
  { check that WHEN expression be of type boolean}
  For I := 0 To ParameterCount - 1 Do
  Begin
    If Param[I].ExprType <> ttBoolean Then
      Raise EExpression.Create( SEXPR_WRONGWHENEXPR );
  End;
  { check that all expression in THEN be of same type }
  For I := 1 To FThenParamList.Count - 1 Do
  Begin
    If Not FThenParamList.Param[I].CanReadAs( FThenParamList.Param[0].ExprType ) Then
      Raise EExpression.Create( SEXPR_WRONGTHENEXPR );
  End;
  If ( FElseExpr <> Nil ) And Not FElseExpr.CanReadAs( FThenParamList.Param[0].ExprType ) Then
    Raise EExpression.Create( SEXPR_WRONGTHENEXPR );
End;

Destructor TCaseWhenElseExpr.Destroy;
Begin
  FThenParamList.Free;
  If FElseExpr <> Nil Then
    FElseExpr.Free;
  Inherited Destroy;
End;

Function TCaseWhenElseExpr.GetAsBoolean: Boolean;
Var
  I: Integer;
Begin
  CheckParameters;
  Result := FALSE;
  For I := 0 To ParameterCount Do
    If Param[I].AsBoolean Then
    Begin
      Result := FThenParamList.AsBoolean[I];
      Exit;
    End;
  If FElseExpr <> Nil Then
    Result := FElseExpr.AsBoolean;
End;

Function TCaseWhenElseExpr.GetAsFloat: Double;
Var
  I: Integer;
Begin
  CheckParameters;
  Result := 0;
  For I := 0 To ParameterCount - 1 Do
    If Param[I].AsBoolean Then
    Begin
      Result := FThenParamList.AsFloat[I];
      Exit;
    End;
  If FElseExpr <> Nil Then
    Result := FElseExpr.AsFloat;
End;

Function TCaseWhenElseExpr.GetAsInteger: Integer;
Var
  I: Integer;
Begin
  CheckParameters;
  Result := 0;
  For I := 0 To ParameterCount Do
    If Param[I].AsBoolean Then
    Begin
      Result := FThenParamList.AsInteger[I];
      Exit;
    End;
  If FElseExpr <> Nil Then
    Result := FElseExpr.AsInteger;
End;

Function TCaseWhenElseExpr.GetMaxString: String;
Var
  I: Integer;
Begin
  Result:= '';
  if not (GetExprtype = ttString) then Exit;
  For I := 0 To ParameterCount - 1 Do
    if Length( FThenParamList.AsString[I] ) > Length( Result ) then
      Result:= FThenParamList.AsString[I];
  If ( FElseExpr <> Nil ) And ( Length( FElseExpr.AsString ) > Length( Result ) ) then
    Result := FElseExpr.AsString;
End;

Function TCaseWhenElseExpr.GetAsString: String;
Var
  I: Integer;
Begin
  CheckParameters;
  Result := '';
  For I := 0 To ParameterCount - 1 Do
    If Param[I].AsBoolean Then
    Begin
      Result := FThenParamList.AsString[I];
      Exit;
    End;
  If FElseExpr <> Nil Then
    Result := FElseExpr.AsString;
End;

Function TCaseWhenElseExpr.GetExprtype: TExprtype;
Begin
  { the expression type is the type of the first expression }
  Result := FThenParamList.ExprType[0];
End;

{TFormatDateTimeExpr - class implementation}

Function TFormatDateTimeExpr.GetAsString: String;
Begin
  Result := FormatDateTime( Param[0].AsString, Param[1].AsFloat );
End;

Function TFormatDateTimeExpr.GetExprType: TExprType;
Begin
  Result := ttString;
End;

{TFormatFloatExpr - class implementation
 FORMATFLOAT('###,###,##0.00', 32767)}

Function TFormatFloatExpr.GetAsString: String;
Begin
  Result := FormatFloat( Param[0].AsString, Param[1].AsFloat );
End;

Function TFormatFloatExpr.GetExprType: TExprType;
Begin
  Result := ttString;
End;

{ TFormatExpr - class implementation
  Format('%d %s ...', 1234, 'ABC', ..., etc) }

Function TFormatExpr.GetAsString: String;
Const
  MAXARGS = 20; {maximum number of arguments allowed (increase if needed)}
Var
  cnt, n: integer;
  ss: Array[0..MAXARGS] Of ShortString;
  ea: Array[0..MAXARGS] Of Extended;
  Vars: Array[0..MAXARGS] Of TVarRec;
Begin
  n := imin( ParameterCount - 1, MAXARGS );
  { first parameter is the format string and the rest are the args}
  For cnt := 1 To n Do
  Begin
    Case Param[cnt].ExprType Of
      ttString:
        Begin
          Vars[cnt - 1].VType := vtString;
          ss[cnt - 1] := Param[cnt].AsString;
          Vars[cnt - 1].VString := @ss[cnt - 1];
        End;
      ttFloat:
        Begin
          Vars[cnt - 1].VType := vtExtended;
          ea[cnt - 1] := Param[cnt].AsFloat;
          Vars[cnt - 1].VExtended := @ea[cnt - 1];
        End;
      ttInteger:
        Begin
          Vars[cnt - 1].VType := vtInteger;
          Vars[cnt - 1].VInteger := Param[cnt].AsInteger;
        End;
      ttBoolean:
        Begin
          Vars[cnt - 1].VType := vtBoolean;
          Vars[cnt - 1].VBoolean := Param[cnt].AsBoolean;
        End;
    End;
  End;
  result := Format( Param[0].AsString, Vars );
End;

Function TFormatExpr.GetExprType: TExprType;
Begin
  result := ttString;
End;

// TDecodeDateTimeExpr implementation

Constructor TDecodeDateTimeExpr.Create( ParameterList: TParameterList;
  DecodeKind: TDecodeKind );
Begin
  Inherited Create( ParameterList );
  FDecodeKind := DecodeKind;
End;

Function TDecodeDateTimeExpr.GetExprType: TExprType;
Begin
  Result := ttInteger;
End;

Function TDecodeDateTimeExpr.GetAsInteger: Integer;
Var
  Year, Month, Day, Hour, Min, Sec, MSec: Word;
Begin
  Case FDecodeKind Of
    dkYear, dkMonth, dkDay: DecodeDate( Param[0].AsFloat, Year, Month, Day );
    dkHour, dkMin, dkSec, dkMSec:
      DecodeTime( Param[0].AsFloat, Hour, Min, Sec, MSec );
  Else
    DecodeDate( Param[0].AsFloat, Year, Month, Day );
  End;
  Case FDecodeKind Of
    dkYear: Result := Year;
    dkMonth: Result := Month;
    dkDay: Result := Day;
    dkHour: Result := Hour;
    dkMin: Result := Min;
    dkSec: Result := Sec;
    dkMSec: Result := MSec;
  Else
    Result := Year;
  End;
End;

{ TDecodeExpr
  DECODE('abc', 'a', 1,
                'b', 2,
                'abc', 3,
                'd', 4,
                -1 )
 }

Constructor TDecodeExpr.Create( ParameterList: TParameterList );
Begin
  Inherited Create( ParameterList );
  { check for valid expressions }
  If ( ParameterList = Nil ) Or ( ( ParameterList.Count Mod 2 ) <> 0 ) Then
    Raise EExpression.Create( 'Incorrect number of arguments' );
End;

Function TDecodeExpr.GetAsBoolean: Boolean;
Var
  I: Integer;
  Found: Boolean;
Begin
  Result := false;
  Found := false;
  I := 1;
  While I < ParameterCount - 1 Do
  Begin
    Case Param[0].ExprType Of
      ttString:
        If Param[0].AsString = Param[I].AsString Then
          Found := true;
      ttFloat:
        If Param[0].AsFloat = Param[I].AsFloat Then
          Found := true;
      ttInteger:
        If Param[0].AsInteger = Param[I].AsInteger Then
          Found := true;
      ttBoolean:
        If Param[0].AsBoolean = Param[I].AsBoolean Then
          Found := true;
    End;
    If found Then
    Begin
      Result := Param[I + 1].AsBoolean;
      break;
    End;
    Inc( I, 2 );
  End;
  If Not found Then
    Result := Param[ParameterCount - 1].AsBoolean;
End;

Function TDecodeExpr.GetAsFloat: Double;
Var
  I: Integer;
  Found: Boolean;
Begin
  Result := 0;
  Found := false;
  I := 1;
  While I < ParameterCount - 1 Do
  Begin
    Case Param[0].ExprType Of
      ttString:
        If Param[0].AsString = Param[I].AsString Then
          Found := true;
      ttFloat:
        If Param[0].AsFloat = Param[I].AsFloat Then
          Found := true;
      ttInteger:
        If Param[0].AsInteger = Param[I].AsInteger Then
          Found := true;
      ttBoolean:
        If Param[0].AsBoolean = Param[I].AsBoolean Then
          Found := true;
    End;
    If found Then
    Begin
      Result := Param[I + 1].AsFloat;
      break;
    End;
    Inc( I, 2 );
  End;
  If Not found Then
    Result := Param[ParameterCount - 1].AsFloat;
End;

Function TDecodeExpr.GetAsInteger: Integer;
Var
  I: Integer;
  Found: Boolean;
Begin
  Result := 0;
  Found := false;
  I := 1;
  While I < ParameterCount - 1 Do
  Begin
    Case Param[0].ExprType Of
      ttString:
        If Param[0].AsString = Param[I].AsString Then
          Found := true;
      ttFloat:
        If Param[0].AsFloat = Param[I].AsFloat Then
          Found := true;
      ttInteger:
        If Param[0].AsInteger = Param[I].AsInteger Then
          Found := true;
      ttBoolean:
        If Param[0].AsBoolean = Param[I].AsBoolean Then
          Found := true;
    End;
    If found Then
    Begin
      Result := Param[I + 1].AsInteger;
      break;
    End;
    Inc( I, 2 );
  End;
  If Not found Then
    Result := Param[ParameterCount - 1].AsInteger;
End;

Function TDecodeExpr.GetMaxString: String;
var
  I, L, MaxL: Integer;
Begin
  L := 2;
  MaxL := Length( Param[L].AsString );
  I := 2;
  While I <= ParameterCount - 1 Do
  Begin
    If Length( Param[I].AsString ) > MaxL Then
    Begin
      L := I;
      MaxL := Length( Param[I].AsString );
    End;
    Inc( I, 2 );
  End;
  Result := Param[L].AsString;
End;

Function TDecodeExpr.GetAsString: String;
Var
  I: Integer;
  Found: Boolean;
Begin
  Found := False;
  I := 1;
  While I < ParameterCount - 1 Do
  Begin
    Case Param[0].ExprType Of
      ttString:
        If Param[0].AsString = Param[I].AsString Then
          Found := true;
      ttFloat:
        If Param[0].AsFloat = Param[I].AsFloat Then
          Found := true;
      ttInteger:
        If Param[0].AsInteger = Param[I].AsInteger Then
          Found := true;
      ttBoolean:
        If Param[0].AsBoolean = Param[I].AsBoolean Then
          Found := true;
    End;
    If found Then
    Begin
      Result := Param[I + 1].AsString;
      break;
    End;
    Inc( I, 2 );
  End;
  If Not found Then
    Result := Param[ParameterCount - 1].AsString;
End;

Function TDecodeExpr.GetExprtype: TExprtype;
Begin
  Result := Param[2].ExprType;
End;

{ MINOF, MAXOF functions support}

Constructor TMinMaxOfExpr.Create( ParameterList: TParameterList; IsMin: Boolean );
Begin
  Inherited Create( ParameterList );
  { check for valid expressions }
  If ( ParameterList = Nil ) Or ( ParameterList.Count < 1 ) Then
    Raise EExpression.Create( 'Incorrect number of arguments' );
  FIsMin := IsMin;
End;

Function TMinMaxOfExpr.GetAsFloat: Double;
Var
  i: Integer;
Begin
  Result := Param[0].AsFloat;
  For i := 1 To ParameterCount - 1 Do
  Begin
    If FIsMin Then
      Result := dMin( Result, Param[i].AsFloat )
    Else
      Result := dMax( Result, Param[i].AsFloat );
  End;
End;

Function TMinMaxOfExpr.GetExprtype: TExprtype;
Begin
  Result := ttFloat;
End;

End.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -