TFunctionParser is a parser for analyzing and evaluating mathematical functions.
The function term is a user given string like 'sin(x)*x'. The function term can be
changed anytime.
TFunctionParser provides more then 90 mathematical intrinsic functions and operations.
The user can define functions, constants and variable names himself.
TFunctionParser was formerly a Delphi component, but with different Delphi versions the binaries were not compatible. Thus we had to compile the sources for each Delphi version (in some cases even the sources were not compatible). So we thought releasing a DLL that encapsulates TFunctionParser would be a good idea and we came to COM/Automation.
Here is Microsoft's Definition:
COM is a platform-independent, distributed, object-oriented system for creating binary software components that can interact. COM is the foundation technology for Microsoft's OLE (compound documents) and ActiveX (Internet-enabled components) technologies, as well as others.
Automation is a COM-based technology that allows developers to create custom applications to automate frequent tasks.
If this is your first contact with COM/Automation you might be a little confused - but you will soon get familiar with it.
Thus TFunctionParser is a software that can be used by software developpers to build their own applications embedding a powerful and comprehensive mathematical parser for quick and easy analyzing and evaluating mathematical functions.
Every programming or scripting language that supports COM can use TFunctionParser: Delphi, C, C++, C#, Perl, VBScript, JavaScript, VBA, ...
TFunctionParser provides the following features:
TFunctionParser 7.0 is Shareware.
You may test it for a period of 30 days.
It may be copied and distributed unmodified (complete ZIP-file, no single files).
If you use it in your non-commercial applications you must register it by sending 20 Euros (cash or traveller's check) to MHGS.
If you want to use TFunctionParser for commercial purposes please contact us.
Registered users of one of the former versions get a discount.
You will obtain a special edition without the automatic initial info screen.
If you are not a registered user the infoscreen will appear each time an instance of TFunctionParser is created. Unregistered use is limited to 30 days. Please note that unregistered use after this evalution period will violate copyright law and international treaties and you will make yourself liable to prosecution.
Our address is:
MHGS eMail: mhgs@MHGSoft.de
Egerlandstr. 18
D-91083 Baiersdorf URL:
http://www.MHGSoft.de
Germany
You are obliged to quote our copyright in all your applications and programs.
When ordering your personal edition please confirm that you read this file and agree to the license conditions. Don't forget your eMail address.
If you find any bug, please don't hesitate to inform us. Details (functions, arguments, ...)
would be helpful.
Any suggestions, questions, and comments are welcome.
---------------------------------- THE LEGAL DISCLAIMER ---------------------------------- THE INFORMATION AND CODE PROVIDED HEREUNDER (COLLECTIVELY REFERRED TO AS "SOFTWARE") IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
The file MHGSPARS.ZIP contains the following files:
MHGSPARS.DLL | Server-DLL |
---|---|
MHGSPARS.TXT | short ASCII formatted Info |
FILE_ID.DIZ | dto. |
README.HTM | this file |
LOGOMHGS.GIF | our logo |
FAVICON.ICO | TFunctionParser Icon |
INSTALL.BAT | installs TFunctionParser (only Win2k/XP), see below |
UNINSTAL.BAT | uninstalls TFunctionParser (only Win2k/XP), see below |
FDEMO.DPR FDEMO1.PAS FDEMO1.DFM | providing a simple demo application for TFunctionParser (function plotter) under Delphi |
CALC.VBP CALC.VBW FORM1.FRM FORM1.FRX | providing a simple demo application of TFunctionParser for Visual Basic |
CALC.HTA | simple demo as Hypertext Application with JavaScript |
CALC.VBS | sample script for using Windows Script Host with VBScript |
CONST.PL | sample script for Perl |
CALC.DOC | sample macro for VBA under MS Word |
CALC.EXL | sample macro for VBA under MS Excel |
Examples for C#.NET and MSVC++ are available directly from us.
The essential file is MHGSPARS.DLL that contains TFunctionParser. It must be copied to your harddisk.This registration process can be done in different ways:
regsvr32 <PATH>\MHGSPARS.DLL
<PATH>
is the path of MHGSPARS.DLL.regsvr32 -u <PATH>\MHGSPARS.DLL
-s
suppresses the display of messageboxes.function DllRegisterServer: HResult; stdcall;
function DllUnregisterServer: HResult; stdcall;
Get a handle to the DLL with LoadLibrary, then call GetProcAddress for obtaining the procedure entry point:
var dllinst: THandle; //Handle of DLL DllRegisterServer: function:HRESULT; //function address installdir:string; //path of installation folder . . dllinst:=LoadLibrary(pchar(installdir+'\mhgspars.dll')); if dllinst=0 then ... //Errorhandling @DllRegisterServer:=GetProcAddress(dllinst,'DllRegisterServer'); DllRegisterServer; . FreeLibrary(dllinst); |
AngleMode | FunctionsText | ShowInfo |
CleanUp | GetVarValue | Term |
ConstantsText | Result | VarNamesText |
ErrorCode | SetVarValue | Version |
ErrorMessage |
Term is a character string (e.g. 'sin(x)') defining the given function.
Spaces are
ignored. Lower or upper cases are not distinguished.
Arguments of functions must
be in brackets.
Multiple arguments in functions must be separated by commata or semicola.
Only relevant for trigonometric functions and their inverses (arc functions). If TFunctionParser.Anglemode is RAD the unit for angles is radians (full angle =2*pi), if it is DEG the unit is degrees (full angle =360°), and if it is GON the unit is gons (full angle =400 gons).
You can define variable names with VarNamesText. Default are x, y, z and t.
Each variable name must stand in a separat line (lines must be separated by CR LF (0xD,0xA)).
You may make comments in the same lines, after a '#'-sign (e.g. 'x #that is x');
If you use multiple TFunctionParser instances they will use the same variable names.
You can define an arbitrary number of constants with ConstantsText
using the notation e.g. 'A1=1.5e-3'.
For TFunctionParser it is even possible to define constants like 'A2=sin(pi/4)' or 'A3=A2-A1'
Warning: The call of variable names (e.g. 'A4=exp(y)') will lead to wrong results.
You may not call constants recursively (e.g. 'A5=sqr(A5+1)') or crosswise
(e.g. 'A6=A7', 'A7=A6').
The constant identifiers must be unique. Otherwise the first one in the list is
taken.
Reserved abbreviations for identifier are e, pi, C, TRUE and FALSE.
The sequence of the definition of the constants doesn't matter. You may even add
your own comments in separat lines.
Lines must be separated by CR LF (0xD,0xA).
ConstantsText is automatically initialized with a list of physical constants. Read the property ConstantsText for obtaining the list. (cf. sample CONST.PL).
If you use multiple TFunctionParser instances they will use the same defined constants.
In this list you can define functions (macros) that are based on the intrinsic
functions. For example: 'F(X;Y)=EXP(X)*COS(Y)'.
You must specify the arguments in brackets and separated by semicola on the left side.
There must be at least one argument.
The programmer is responsible for correct syntax and unique identifiers.
Userdefined functions may depend on other userdefined funclions, like e.g.
'G(X)=SQR(F(X;PI))
Recursive or crosswise calls are not allowed.
Warning: If you use identifiers of predefined functions (e.g. SIN(X)) the latter
ones are overwritten.
Your own comments may be included after a '#'-sign.
Lines must be separated by CR LF (0xD,0xA).
If you use multiple TFunctionParser instances they will use the same defined functions.
See CALC.VBS for a sample how to use the FunctionText property.
When you read the Result, the Term is evaluated and the function value returned.
If an error occurs the ErrorCode is set according to the following list:
0 | everything is OK |
1 | wrong parentheses / separators |
2 | Syntax error / invalid term |
3 | unknown identifier |
4 | recursive function or constant |
5 | wrong number of operands |
6 | term is not analyzed |
7 | function is not defined for argument(s) |
8 | NaN: evaluation aborted |
9 | declarations not assigned |
You should check ErrorCode after assigning the term and after reading the result.
The Errormessage gives you detailed verbose information on the errors that occured.
Version indicates the used version.
You can define the variable value of any variable defined in the VarNamesText property.
the name of the variable.
Valuethe numerical value of the variable.
GetVarValue returns the value of any variable that is defined in the VarNamesText property.
the name of the variable.
Valuethe numerical value of the variable.
ShowInfo displays the about screen.
If you do not nead TFunctionParser anymore and don't want to rely on garbage collection you can call CleanUp to free used resources. Warning: If you use TFunctionParser afterwards this can lead to an access violation.
The first character must be alphabetical. The remaining characters may be alphabetic or numerical. Special symbols are not supported (except underscore). Identifiers must be unique.
For working with TFunctionParser you should perform the following steps:
Necessary steps are indicated by consecutive numbers. Letters mark optional steps that may
be omitted if you don't want to use the respective features.
Please note that TFunctionParser must be installed on the respective computer.
(*1*) | Create a TFunctionParser Object. The HowTo depends on your automation client. See the respective reference for more information. |
(*A*) | Define Variables using the VarNamesText property (optional). |
(*B*) | Define Constants using the ConstantsText property (optional). |
(*C*) | Define Functions using the FunctionsText property (optional). |
(*D*) | Change the AngleMode using the AngleMode property (optional). |
(*2*) | Set the Term property to the desired function term. |
(*E*) | Check the ErrorCode or ErrorMessage (optional). |
(*3*) | Set all required variable values using SetVarValue. If you don't use variables you can omit this step. |
(*4*) | Read the Result. |
(*F*) | Check the ErrorCode or ErrorMessage (optional). |
Attached to the MHGSPARS.ZIP file there are multiple sample scripts or programs.
Some of them are quite easy. They are only intented to demonstrate the general access on TFunctionParser in the respective language. If you have sufficient knowledge in the respective client language you should have no problems to modify and expand the listings for suiting your own wishes.
Some samples are a little more complex to show the capabilities of TFunctionParser.
The following Delphi listing shows the general use of TFunctionParser.
A simple calculator program may contain the following code.
Clicking on a button will induce the program to read the function term and the variable
value from the respective edit fields, evaluate these, and write the result as the
caption of a label.
... uses ComObj; var FunctionParser:VARIANT; procedure TForm1.FormCreate(Sender: TObject); begin FunctionParser:=CreateOleObject('mhgspars.FunctionParser'); //(*1*) end; procedure TForm1.BitBtn1Click(Sender: TObject); begin FunctionParser.Term:=edit1.text; //(*2*) {e.g. Term:='sin(x)/x'} FunctionParser.SetVarValue('x',strtofloat(edit2.text)); //(*3*) {'x' must be defined as variable name} label1.caption:='Result = '+floattostr(FunctionParser.Result); //(*4*) if FunctionParser.ErrorCode<>0 then label1.caption:=FunctionParser.ErrorMessage; //(*F*) {It is indeed that easy to program a calculator} end; ... |
The separator between multiple arguments in functions is the comma (,) or the semicolon (;). The decimal separator is the period (.).
The fourth column specifies the availability for TFunctionParser.