Browse Source

* Patch by Werner Pamler to delete builtin (bug ID 36396)

git-svn-id: trunk@43636 -
michael 5 years ago
parent
commit
575fd849b1
2 changed files with 45 additions and 0 deletions
  1. 15 0
      packages/fcl-base/src/fpexprpars.pp
  2. 30 0
      packages/fcl-base/tests/testexprpars.pp

+ 15 - 0
packages/fcl-base/src/fpexprpars.pp

@@ -807,6 +807,8 @@ Type
     Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionCallBack) : TFPBuiltInExprIdentifierDef;
     Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionEvent) : TFPBuiltInExprIdentifierDef;
     Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ANodeClass : TFPExprFunctionClass) : TFPBuiltInExprIdentifierDef;
+    Procedure Delete(AIndex: Integer);
+    Function Remove(aIdentifier : String) : Integer;
     Property IdentifierCount : Integer Read GetCount;
     Property Identifiers[AIndex : Integer] :TFPBuiltInExprIdentifierDef Read GetI;
   end;
@@ -2299,6 +2301,7 @@ begin
   Result.FNodeType:=ANodeClass;
 end;
 
+
 { ---------------------------------------------------------------------
   TFPExprIdentifierDef
   ---------------------------------------------------------------------}
@@ -2667,6 +2670,18 @@ begin
   Result. Category:=ACategory;
 end;
 
+procedure TExprBuiltInManager.Delete(AIndex: Integer);
+begin
+  FDefs.Delete(AIndex);
+end;
+
+function TExprBuiltInManager.Remove(aIdentifier: String): Integer;
+begin
+  Result:=IndexOfIdentifier(aIdentifier);
+  if Result<>-1 then
+    Delete(Result);
+end;
+
 
 { ---------------------------------------------------------------------
   Various Nodes

+ 30 - 0
packages/fcl-base/tests/testexprpars.pp

@@ -884,6 +884,8 @@ type
     procedure TestVariable7;
     procedure TestFunction1;
     procedure TestFunction2;
+    procedure TestDelete;
+    procedure TestRemove;
   end;
 
   TTestBuiltins = Class(TTestExpressionParser)
@@ -5845,6 +5847,34 @@ begin
   AssertNull('FindIdentifier returns no result',I2);
 end;
 
+procedure TTestBuiltinsManager.TestDelete;
+
+begin
+  FM.AddFunction(bcUser,'EchoDate','D','D',@EchoDate);
+  FM.AddFunction(bcUser,'EchoDate2','D','D',@EchoDate);
+  FM.AddFunction(bcUser,'EchoDate3','D','D',@EchoDate);
+  AssertEquals('Count before',3,FM.IdentifierCount);
+  FM.Delete(2);
+  AssertEquals('Count after',2,FM.IdentifierCount);
+  AssertEquals('No more',-1,FM.IndexOfIdentifier('EchoDate3'));
+  AssertEquals('Left 1',0,FM.IndexOfIdentifier('EchoDate'));
+  AssertEquals('Left 2',1,FM.IndexOfIdentifier('EchoDate2'));
+end;
+
+procedure TTestBuiltinsManager.TestRemove;
+begin
+  FM.AddFunction(bcUser,'EchoDate','D','D',@EchoDate);
+  FM.AddFunction(bcUser,'EchoDate2','D','D',@EchoDate);
+  FM.AddFunction(bcUser,'EchoDate3','D','D',@EchoDate);
+  AssertEquals('Count before',3,FM.IdentifierCount);
+  AssertEquals('Result ',1,FM.Remove('EchoDate2'));
+  AssertEquals('Count after',2,FM.IdentifierCount);
+  AssertEquals('No more',-1,FM.IndexOfIdentifier('EchoDate2'));
+  AssertEquals('Left 1',0,FM.IndexOfIdentifier('EchoDate'));
+  AssertEquals('Left 2',1,FM.IndexOfIdentifier('EchoDate3'));
+  AssertEquals('Result ',-1,FM.Remove('Nono'));
+end;
+
 { TTestBuiltins }
 
 procedure TTestBuiltins.Setup;