Delphi

 

Adding uCalc to your Delphi application

 

In order to implement uCalc Fast Math Parser in Delphi, follow these simple steps:

 

  1. Copy uCalcDlp.pas to your project directory, or an appropriate include directory.
  2. Place uCalc DLLs either in the Windows System directory, your project directory, or a suitable directory that is in the path.
  3. Add the word uCalcDlp to the list of units under the uses section of your project.

 

Now you're all set to go.

 

 

Demo program

 

The name of the uCalc demo project file to load into Delphi is DemoDlph.dpr.The uCalc-related source code you should browse through is found in DemoDlp.pas.This source code demonstrates the essential features, especially as they relate to Delphi.

 

 

Standard Call

 

It is very important to always remember to use the Standard Call convention for all uCalc callbacks.For example:

 

function MyErrorHandler(t: Longword): Longword; stdcall;

procedure MyArea(Expr: Longword); stdcall;

function MyEasyCallback(a: Double; var b: Longint; c: Byte): Extended; stdcall;

 

 

Data type considerations

 

uCalc supports various data types.The nomenclature for these types varies widely from compiler to compiler.If you are using non-native callback definitions, then it is important to make sure that the data types of your Delphi callbacks match the correct uCalc data types.uCalc's default String type, which is a dynamic multi-byte string type, matches Delphi's AnsiString type.uCalc uses Extended as the default numeric type, whereas uCalc uses Double for some of the other compilers.If you are defining variables, or native callback routines, it is not necessary to specify a numeric type, unless you specifically need a type other than the default Extended type.

 

 

Examples:

 

The following examples are for key features that may have some peculiarities in Delphi.There are many more examples in Visual Basic that are general enough that a Delphi counter-part was not included.

 

Example 1:Simple evaluation with ucEvalStr

Example 2:Fast evaluation millions of times in a loop

Example 3:Defining a centralized error handler

Example 4:Raising an error with ucRaiseErrorMessage

Example 5:Allowing your compiler to catch an exception (ucReRaise)

Example 6:A native function callback with two numeric arguments

Example 7:A native function callback with any number of arguments

Example 8:A native string callback function

Example 9:A non-native function callback

Example 10:Strings in non-native functions

Example 11:Attached variables

 

See More Examples

 

New or enhanced in version 2.96

         Nothing Delphi-related.

         See also What�s New.

 

New or enhanced in version 2.96

 

New or enhanced in version 2.9+

ucDefineFunction('Area(Length, Width)", Longword(@MyArea));

you can now simply do:��

ucDefineFunction('Area(ByVal Length As Extended, ByVal Width As Extended)", @MyArea);