📄 dbf_prsdef.pas
字号:
function TExprWord.IsFunction: Boolean;
begin
Result := False;
end;
procedure TExprWord.SetFixedLen(NewLen: integer);
begin
end;
{ TConstant }
constructor TConstant.Create(AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
begin
inherited Create(AName, AExprFunc);
FResultType := AVarType;
end;
function TConstant.GetResultType: TExpressionType;
begin
Result := FResultType;
end;
{ TFloatConstant }
constructor TFloatConstant.Create(AName, AValue: string);
begin
inherited Create(AName, etFloat, _FloatVariable);
if Length(AValue) > 0 then
FValue := StrToFloat(AValue)
else
FValue := 0.0;
end;
constructor TFloatConstant.CreateAsDouble(AName: string; AValue: Double);
begin
inherited Create(AName, etFloat, _FloatVariable);
FValue := AValue;
end;
function TFloatConstant.AsPointer: PChar;
begin
Result := PChar(@FValue);
end;
{ TUserConstant }
constructor TUserConstant.CreateAsDouble(AName, Descr: string; AValue: Double);
begin
FDescription := Descr;
inherited CreateAsDouble(AName, AValue);
end;
function TUserConstant.GetDescription: string;
begin
Result := FDescription;
end;
{ TStringConstant }
constructor TStringConstant.Create(AValue: string);
var
firstChar, lastChar: Char;
begin
inherited Create(AValue, etString, _StringConstant);
firstChar := AValue[1];
lastChar := AValue[Length(AValue)];
if (firstChar = lastChar) and ((firstChar = '''') or (firstChar = '"')) then
FValue := Copy(AValue, 2, Length(AValue) - 2)
else
FValue := AValue;
end;
function TStringConstant.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{ TBooleanConstant }
constructor TBooleanConstant.Create(AName: string; AValue: Boolean);
begin
inherited Create(AName, etBoolean, _BooleanVariable);
FValue := AValue;
end;
function TBooleanConstant.AsPointer: PChar;
begin
Result := PChar(@FValue);
end;
{ TIntegerConstant }
constructor TIntegerConstant.Create(AValue: Integer);
begin
inherited Create(IntToStr(AValue), etInteger, _IntegerVariable);
FValue := AValue;
end;
function TIntegerConstant.AsPointer: PChar;
begin
Result := PChar(@FValue);
end;
{ TVariable }
constructor TVariable.Create(AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
begin
inherited Create(AName, AExprFunc);
FResultType := AVarType;
end;
function TVariable.GetCanVary: Boolean;
begin
Result := True;
end;
function TVariable.GetResultType: TExpressionType;
begin
Result := FResultType;
end;
{ TFloatVariable }
constructor TFloatVariable.Create(AName: string; AValue: PDouble);
begin
inherited Create(AName, etFloat, _FloatVariable);
FValue := AValue;
end;
function TFloatVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{ TStringVariable }
constructor TStringVariable.Create(AName: string; AValue: PPChar);
begin
// variable or fixed length?
inherited Create(AName, etString, _StringVariable);
// store pointer to string
FValue := AValue;
FFixedLen := -1;
end;
function TStringVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
function TStringVariable.GetFixedLen: Integer;
begin
Result := FFixedLen;
end;
function TStringVariable.LenAsPointer: PInteger;
begin
Result := @FFixedLen;
end;
procedure TStringVariable.SetFixedLen(NewLen: integer);
begin
FFixedLen := NewLen;
end;
{ TDateTimeVariable }
constructor TDateTimeVariable.Create(AName: string; AValue: PDateTimeRec);
begin
inherited Create(AName, etDateTime, _DateTimeVariable);
FValue := AValue;
end;
function TDateTimeVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{ TIntegerVariable }
constructor TIntegerVariable.Create(AName: string; AValue: PInteger);
begin
inherited Create(AName, etInteger, _IntegerVariable);
FValue := AValue;
end;
function TIntegerVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{$ifdef SUPPORT_INT64}
{ TLargeIntVariable }
constructor TLargeIntVariable.Create(AName: string; AValue: PLargeInt);
begin
inherited Create(AName, etLargeInt, _LargeIntVariable);
FValue := AValue;
end;
function TLargeIntVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{$endif}
{ TBooleanVariable }
constructor TBooleanVariable.Create(AName: string; AValue: PBoolean);
begin
inherited Create(AName, etBoolean, _BooleanVariable);
FValue := AValue;
end;
function TBooleanVariable.AsPointer: PChar;
begin
Result := PChar(FValue);
end;
{ TLeftBracket }
function TLeftBracket.GetResultType: TExpressionType;
begin
Result := etLeftBracket;
end;
{ TRightBracket }
function TRightBracket.GetResultType: TExpressionType;
begin
Result := etRightBracket;
end;
{ TComma }
function TComma.GetResultType: TExpressionType;
begin
Result := etComma;
end;
{ TExpressList }
constructor TExpressList.Create;
begin
inherited;
FShortList := TExpressShortList.Create;
end;
destructor TExpressList.Destroy;
begin
inherited;
FShortList.Free;
end;
procedure TExpressList.Add(Item: Pointer);
var
I: Integer;
begin
inherited;
{ remember we reference the object }
Inc(TExprWord(Item).FRefCount);
{ also add ShortName as reference }
if Length(TExprWord(Item).ShortName) > 0 then
begin
FShortList.Search(FShortList.KeyOf(Item), I);
FShortList.Insert(I, Item);
end;
end;
function TExpressList.Compare(Key1, Key2: Pointer): Integer;
begin
Result := StrIComp(PChar(Key1), PChar(Key2));
end;
function TExpressList.KeyOf(Item: Pointer): Pointer;
begin
Result := PChar(TExprWord(Item).Name);
end;
procedure TExpressList.FreeItem(Item: Pointer);
begin
Dec(TExprWord(Item).FRefCount);
FShortList.Remove(Item);
if TExprWord(Item).FRefCount = 0 then
inherited;
end;
function TExpressList.Search(Key: Pointer; var Index: Integer): Boolean;
var
SecIndex: Integer;
begin
Result := inherited Search(Key, Index);
if not Result then
begin
Result := FShortList.Search(Key, SecIndex);
if Result then
Index := IndexOf(FShortList.Items[SecIndex]);
end;
end;
function TExpressShortList.Compare(Key1, Key2: Pointer): Integer;
begin
Result := StrIComp(PChar(Key1), PChar(Key2));
end;
function TExpressShortList.KeyOf(Item: Pointer): Pointer;
begin
Result := PChar(TExprWord(Item).ShortName);
end;
procedure TExpressShortList.FreeItem(Item: Pointer);
begin
end;
{ TExprCollection }
procedure TExprCollection.Check;
var
brCount, I: Integer;
begin
brCount := 0;
for I := 0 to Count - 1 do
begin
case TExprWord(Items[I]).ResultType of
etLeftBracket: Inc(brCount);
etRightBracket: Dec(brCount);
end;
end;
if brCount <> 0 then
raise EParserException.Create('Unequal brackets');
end;
procedure TExprCollection.EraseExtraBrackets;
var
I: Integer;
brCount: Integer;
begin
if (TExprWord(Items[0]).ResultType = etLeftBracket) then
begin
brCount := 1;
I := 1;
while (I < Count) and (brCount > 0) do
begin
case TExprWord(Items[I]).ResultType of
etLeftBracket: Inc(brCount);
etRightBracket: Dec(brCount);
end;
Inc(I);
end;
if (brCount = 0) and (I = Count) and (TExprWord(Items[I - 1]).ResultType =
etRightBracket) then
begin
for I := 0 to Count - 3 do
Items[I] := Items[I + 1];
Count := Count - 2;
EraseExtraBrackets; //Check if there are still too many brackets
end;
end;
end;
{ TFunction }
constructor TFunction.Create(AName, AShortName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType;
AExprFunc: TExprFunc; Descr: string);
begin
//to increase compatibility don't use default parameters
FDescription := Descr;
FShortName := AShortName;
InternalCreate(AName, ATypeSpec, AMinFuncArg, AResultType, AExprFunc, false, 0);
end;
constructor TFunction.CreateOper(AName, ATypeSpec: string; AResultType: TExpressionType;
AExprFunc: TExprFunc; AOperPrec: Integer);
begin
InternalCreate(AName, ATypeSpec, -1, AResultType, AExprFunc, true, AOperPrec);
end;
procedure TFunction.InternalCreate(AName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType;
AExprFunc: TExprFunc; AIsOperator: Boolean; AOperPrec: Integer);
begin
inherited Create(AName, AExprFunc);
FMaxFunctionArg := Length(ATypeSpec);
FMinFunctionArg := AMinFuncArg;
if AMinFuncArg = -1 then
FMinFunctionArg := FMaxFunctionArg;
FIsOperator := AIsOperator;
FOperPrec := AOperPrec;
FTypeSpec := ATypeSpec;
FResultType := AResultType;
// check correctness
if FMaxFunctionArg > MaxArg then
raise EParserException.Create('Too many arguments');
end;
function TFunction.GetDescription: string;
begin
Result := FDescription;
end;
function TFunction.GetIsOperator: Boolean;
begin
Result := FIsOperator;
end;
function TFunction.GetMinFunctionArg: Integer;
begin
Result := FMinFunctionArg;
end;
function TFunction.GetMaxFunctionArg: Integer;
begin
Result := FMaxFunctionArg;
end;
function TFunction.GetResultType: TExpressionType;
begin
Result := FResultType;
end;
function TFunction.GetShortName: string;
begin
Result := FShortName;
end;
function TFunction.GetTypeSpec: string;
begin
Result := FTypeSpec;
end;
function TFunction.IsFunction: Boolean;
begin
Result := True;
end;
{ TVaryingFunction }
function TVaryingFunction.GetCanVary: Boolean;
begin
Result := True;
end;
{ TDynamicType }
constructor TDynamicType.Create(DestMem, DestPos: PPChar; ASize: PInteger);
begin
inherited Create;
FMemory := DestMem;
FMemoryPos := DestPos;
FSize := ASize;
end;
procedure TDynamicType.Rewind;
begin
FMemoryPos^ := FMemory^;
end;
procedure TDynamicType.AssureSpace(ASize: Integer);
begin
// need more memory?
if ((FMemoryPos^) - (FMemory^) + ASize) > (FSize^) then
Resize((FMemoryPos^) - (FMemory^) + ASize, False);
end;
procedure TDynamicType.Resize(NewSize: Integer; Exact: Boolean);
var
tempBuf: PChar;
bytesCopy, pos: Integer;
begin
// if not exact requested make newlength a multiple of ArgAllocSize
if not Exact then
NewSize := NewSize div ArgAllocSize * ArgAllocSize + ArgAllocSize;
// create new buffer
GetMem(tempBuf, NewSize);
// copy memory
bytesCopy := FSize^;
if bytesCopy > NewSize then
bytesCopy := NewSize;
Move(FMemory^^, tempBuf^, bytesCopy);
// save position in string
pos := FMemoryPos^ - FMemory^;
// delete old mem
FreeMem(FMemory^);
// assign new
FMemory^ := tempBuf;
FSize^ := NewSize;
// assign position
FMemoryPos^ := FMemory^ + pos;
end;
procedure TDynamicType.Append(Source: PChar; Length: Integer);
begin
// make room for string plus null-terminator
AssureSpace(Length+4);
// copy
Move(Source^, FMemoryPos^^, Length);
Inc(FMemoryPos^, Length);
// null-terminate
FMemoryPos^^ := #0;
end;
procedure TDynamicType.AppendInteger(Source: Integer);
begin
// make room for number
AssureSpace(12);
Inc(FMemoryPos^, GetStrFromInt(Source, FMemoryPos^));
FMemoryPos^^ := #0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -