Răsfoiți Sursa

* Some more explanations

git-svn-id: trunk@12011 -
michael 17 ani în urmă
părinte
comite
c85ce877fb
1 a modificat fișierele cu 38 adăugiri și 0 ștergeri
  1. 38 0
      packages/fcl-base/examples/fpexprpars.txt

+ 38 - 0
packages/fcl-base/examples/fpexprpars.txt

@@ -99,4 +99,42 @@ match. If no match is found, Def will be returned. From this it follows that
 2) The types of Tag, label1, label2 must be the same;
 3) The types of Def, Value1, Value2 must be the same;
 
+As soon as the expression is set, it is compiled and checked. Thus
+   FP.Expression:='1*2';
+will work.
+
+On the other hand
+   FP.Expression:=' 1 * ''a string''';
+will result in an exception because 1 and ''a string'' do not have the same
+type.
+
+Getting the result is quite simple
+
+  FP.Expression:='1*2';
+  Writeln(FP.AsInteger);
+
+This will raise an exception if the type of the result is not integer.
+
+In case the expression result type is unknown, it can be examined using 
+the ResultType function, as in :
+
+  FP.Expression:='Some user-provided expression';
+  Case FP.ResultType of
+    rtString  : Writeln(FP.Evaluate.ResString);
+    rtInteger : Writeln(FP.Evaluate.ResInteger);
+    rtFloat   : Writeln(FP.Evaluate.ResFloat);
+    rtBoolean : Writeln(FP.Evaluate.ResBoolean);
+    rtDateTime : Writeln(FormatDateTime('cccc',FP.Evaluate.ResDateTime));
+  end;   
+
+Which is equivalent to
+
+  FP.Expression:='Some user-provided expression';
+  Case FP.ResultType of
+    rtString  : Writeln(FP.AsString);
+    rtInteger : Writeln(FP.AsInteger);
+    rtFloat   : Writeln(FP.AsFloat);
+    rtBoolean : Writeln(FP.AsBoolean);
+    rtDateTime : Writeln(FormatDateTime('cccc',FP.AsDateTime));
+  end;