📄 artformula.html
字号:
<body>
<p><b><font size=4 color='navy'>ArtFormula v1.1</font></b>
<hr size=2 width="100%" noshade style='color:blue' align=center>
<p><b>ArtFormula package</b> contains
two nonvisual Delphi component for symbolic expression parsing and evaluation.
Provides runtime scripting engine for automating your programs.
<p><b><font size=4 color='navy'>TArtFormula description</font></b>
<p><b><font size=4>Properties:</b></font>
<p><b>property</b> Error :
TFormulaError; - returns current error code.
<p>TFormulaError = (ER_Ok, ER_ILLEGAL, ER_UNKNOWN, ER_RIGHT,
ER_LEFT, ER_SYNTAX, ER_VARS, ER_NOTENOUGH);
<p><b>property</b> ErrPos : integer; -
returns position of error.
<p><b>property</b> ErrLine : integer;
- returns the line with error.
<p><b>property</b> ErrStrPos :
integer; - returns the position of error inside source string.
<p><b>property</b> Stop : boolean; -
set Stop to true during computation to stop.
<p><b>property</b> Compiled : string;
- byte code of compiled source string.
<p><b><font size=4>Published properties:</font></b>
<p><b>property</b> UnQuotedString :
boolean; - if true, ArtFormula will consider unknown identifiers as string
literals.
<p><b>property</b> TestUsedVars :
boolean; - if true, ArtFormula will test whether all external variables, passed
as vars parameter of Compile or Test procedure, are used in source expression.
<p><b>property</b> CaseSensitive :
boolean; - if true, ArtFormula will distinguish case of characters in variables
name. Note: functions names are always case insensitive.
<p><b>property</b> Step : boolean; -
if true, you can stop computation, by setting Stop property to true. If false
you can't stop computation until it ends.
<p><b>property</b> CaseSensitiveString
: boolean; - if true, ArtFormula will distinguish case of string characters in
comparison operations and in pos function.
<p><b>property</b> ExternGetVar :
boolean; - if set, ArtFormula will use GetVarValue and GetVarsCount events to
evaluate unspecified external variables.
<p><b>property</b> VarNameLiterals :
string; - defines set of literals, allowed for variable names.
<p><b><font size=4>Methods:</font></b>
<p><b>procedure</b> SetVar(name :
string; value : PCalcItem); - sets value of variable, given by name parameter.
<p><b>function</b> GetVar(name :
string) : PCalcItem; - returns value of variable.
<p><b>function</b> IncVar(name :
string) : PCalcItem; - increments value of a variable.
<p><b>function</b> DecVar(name :
string) : PCalcItem; - decrements value of a variable.
<p><b>procedure</b> AddVar(name : string;
value : PCalcItem); - adds internal variable.
<p><b>procedure</b>
AddUserConstant(name, value : string); - adds new constant.
<p><b>function</b>
AddUserFunction(name : string; paramcount:integer; fun : pformulafunction;
ismodule:boolean=false):PTableItem; - adds user function (see Section creating
user functions and modules).
<p><b>function</b>
AddModuleFunction(module: PTableItem; name : string; paramcount:integer; fun :
pformulafunction; ismodule:boolean=false):PTableItem; - adds module function
(see Section creating user functions and modules).
<p><b>function</b> Test(instr :
string; num : byte = 0; vars : PStringArray = nil) : boolean; - tests syntax of
source code represented by instr. External variable names are passed as vars
parameter, num specifies number of external variables. Returns true if there
are no errors.
<p><b>function</b> Compile(instr :
string; num : byte = 0; vars : PStringArray = nil) : string; - compiles source
string and returns compiled byte code. On error raises exception.
<p><b>function</b> ComputeN(num : byte
= 0; vals : PCalcArray = nil) : double; - compute previously compiled program
and returns result as numeric value. Values of extern variables are passed in
vals parameter, the number of values is passed in num value.
<p><b>function</b> Compute(num : byte
= 0; vals : PCalcArray = nil) : string; - compute previously compiled program
and returns result as string value.
<p><b>function</b> ComputeStrN(instr :
string; num : byte = 0; vars : PStringArray = nil; vals : PCalcArray = nil) :
double; - compiles and computes source string. Returns result as numeric value.
<p><b>function</b> ComputeStr(instr :
string; num : byte = 0; vars : PStringArray = nil; vals : PCalcArray = nil) :
string; - compiles and computes source string. Returns result as string value.
<p><b>procedure</b> StartGetVars(n :
integer); - starts new parameters evaluation for variable argument list
function (see Section creating user functions and modules).
<p><b>function</b> GetNextVar(var x :
TCalcItem) : boolean; - evaluates next variable argument list function parameter.
Returns false for last value (see Section creating user functions and modules).
<p><b><font size=4>Events:</font></b>
<p><b>property</b> GetVarsCount :
TArtFormulaGetVarsCountProc;<br>
TArtFormulaGetVarsCountProc = <b>procedure</b>(Vname:string; var count:integer;
wantnumber:boolean=false) of object;<br>
If you set <b>ExternGetVars</b> all unknown identifiers will treated as
external variables. To evaluate them you should implement <b>GetVarsCount</b>
and <b>GetVarValue</b> event handlers. <b>GetVarsCount</b> should return in <b>count</b>
parameter number of values associated with <b>Vname</b> variable. Value of <b>wantnumber</b>
specifies whether <b>ArtFormula</b> expects numerical values.
<p><b>property</b> GetVarValue :
TArtFormulaGetVarProc;<br>
TArtFormulaGetVarProc = <b>procedure</b>(Vname:string; n : integer; var
Val:string; wantnumber:boolean=false) of object;<br>
<b>GetVarValue</b> should return in <b>Val</b> parameter <b>n</b>-th value
associated with <b>Vname</b> variable. <b>n</b> will change from 0 to <b>count</b>-1
where <b>count</b> returned by <b>GetVarsCount</b> event. Value of <b>wantnumber</b>
specifies whether <b>ArtFormula</b> expects numerical values.
<p><b>Note.</b> Using <b>GetVarsCount</b>
and <b>GetVarValue</b> you can implement for example range calculation in
spreadsheet application when one parameter passed in variant argument list
function associated with number of cells.
<p><b>Note.</b> For fixed argument
list function <b>ArtFormula</b> will evaluate only first value associated with
variable.
<hr size=2 width="100%" align=center>
<p><b><font size=4 color='navy'>How to use</font></b>
<p>Write ArtFormula program (see Section ArtFormula Syntax).
Prepare string array with external variable names.
<p><b>Note.</b> If you set <b>ExternGetVars</b>
all unknown identifiers will treated as external variables. To evaluate them
you should implement <b>GetVarsCount</b> and <b>GetVarValue</b> event handlers.
<p>Prepare TCalcArray with variable values. Use <b>setN</b>
and <b>setS</b> procedures.
<p>TFormulaDataType = (fdtnumber, fdtstring, fdtgetvar); <br>
<br>
TCalcItem = record <br>
data : double; <br>
str : string; <br>
typ : TFormulaDataType; <br>
end; <br>
<br>
TCalcArray = array of TCalcItem; <br>
PCalcArray = ^TCalcArray;
<p>Use <b>AddUserConstant</b>, <b>AddUserFunction</b> and <b>AddModuleFunction</b>
procedures to add constants, user and module functions.
<p>Call <b>Test</b> and/or <b>Compile</b> procedures passing
source code as <b>instr</b> parameter, number of external variables in <b>num</b>
parameter and pointer to array of variable names in <b>vars</b> parameter. If
there no errors, call <b>Compute</b> or <b>ComputeN</b> (depending on desirable
result type) procedure, passing number of values in <b>num</b> parameter and
pointer to variable values in <b>vals</b> parameter.
<p>To compile and compute expression by one call use <b>ComputeStrN</b>
or <b>ComputeStr</b> procedures.
<hr size=2 width="100%" align=center>
<p><b><font size=4 color='navy'>Creating user functions and modules</font></b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -