Delphi 10.1 BerlinTable of ContentsInstall in CBuilder
C++ Builder Example

Using Math Parser in C++ Builder

For those of you who know C++, but are not very familiar with Delphi, here is a C++ Builder Example that shows how to create a custom function that takes 3 parameters and use it in the expression.

In bcParser.hpp, we have the following definitions:

virtual void __fastcall
CreateNParamFunc(const AnsiString name, TNParamFunc procAddr, int nParam);

we also have:

typedef Extended __fastcall (*TNParamFunc)(const Extended * x, const int x_Size);

Therefore, you define a function as:

Extended __fastcall
sumof3(const Extended * x, const int x_Size)
         return x[0]+x[1]+x[2];

//And use it as:

void __fastcall TForm1::Button1Click(TObject *Sender)
           bcParser1->Expression = Edit1->Text;
                   //define a 3 parameter function.
                   bcParser1->CreateNParamFunc("SUM3", sumof3, 3);
           Label1->Caption = FloatToStr(bcParser1->Value);

C++ Builder Rocks!