Using TMS Analytics & Physics Pack with C++Builder 10.4.2

I am a happy user of TMS Analytics & Phisics Pack version 3.1.0.0, with Delphi (Rad Stutio 10.4.2), and I would like to start using it with C++ Builder as well, so I tried to generate a small test program, but I immediately got stuck simply instantiating an object of type TTranslator

A minimal source (unit1.cpp):

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <Analytix.Translator.hpp>; //it contains the class PASCALIMPLEMENTATION TTranslator definition
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TTranslator *translator = new TTranslator();
}
//---------------------------------------------------------------------------

the compiler returns the following error:s

[bcc32c Error] Mathematix.Base.hpp (76): 'Types' is not a class, namespace, or enumeration,
(+ others errors depending on this)

where line 76 of Mathematix.Base.hpp file is:

typedef Base::Types::TFloat __fastcall (* _dt_Mathematix_Base_1) (const Base::Types::TFloat x);

The Analytix.Translator.hpp file calls many other include files, but I'm not sure if the include of this one is enough,
Can anyone help me out? A minimal working demo for C++ Builder would be very useful :smiley.

At this moment, we only test and validate against Delphi.
The HPP files are automatically generated by the Delphi compiler and are supposed to be correct, we do not have control over HPP file generation.
We will try to allocate time to investigate C++Builder compatibility closer but for now, this wasn't in the scope of the product. It would indeed be nice if we can also support C++Builder, so we will try this with this objective.
Maybe the IDE didn't add automatically the full set of required HPP files. Can you meanwhile try to add manually the other HPP files that define the classes in Mathematix.Base.hpp?

Thanks for the reply.
I will be doing tests in the direction suggested in the next few days (actually some tests I had already done), and I will come back to this thread if I have some results.

It took some time, but I think I have found a solution; description below:

Some important dots:

  • I was able to use the library with C ++ Builder 11, not with version 10.4.2;
  • The library installation program does not generate the .hpp files necessary for use with C ++ Builder (-JL option for the Delphi compiler);
  • I had to have the .hpp files generated and also modified to allow the library to work with C ++ Builder 11

To generate the .hpp files I created a C ++ Builder project and added all the .pas files composing!
the various libraries:

Progetto

Then in the C ++ project I set the generation of all files for C ++ Builder:

Of course, the other paths can also be set, according to your needs (I didn't do it).
I set the compilation order (right click on the project name in the project manager, then select “Build Order” on the context menu) according to the dependencies reported in the documentation pdfs; so first DRTE, then Mathematics, Analytics, etc.

I compiled the project before inserting any other code with the C ++ language. At this point I got the .hpp files in the same folders as the .pas, plus dcu and .obj files in the win32 (or win64) project’s folder. No errors obtained so far.

I then added a button to the project, and the code to create the TTranslator object in the Click event; next, I’ve added the related include <Analytix.Utilities.hpp> header in unit1.cpp.

Next, I compiled, but I’ve got many errors like those I’ve already reported in the first post ('Types' is not a class, namespace, or enumeration). To solve these problems (I wouldn't call them errors) I made the following substitutions in the .hpp files (I recommend keeping copies of the original files):

  1. “Base::Types::TFloat” replaced with “TSystemFloat”
  2. “Base::Types::TCharSet” replaced with “TCharSet”
  3. “Base::Types::TClassArray” replaced with “TClassArray”
  4. “Base::Types::TStringArray” replaced with “TStringArray”
  5. “Base::Types::TObjectArray” replaced with “TObjectArray”

Finally I commented the “using namespace” clauses in the Base.Assemblies.hpp, Base.Utilities.hpp and Base.Symbols.hpp files.

Once this was done, I compiled again and I had no more errors; Success!

below is the source of a minimal test project (unit1.cpp), with logic extracted from the demo analytics VCL in pascal:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <Analytix.Translator.hpp>
#include <Analytix.Utilities.hpp>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{

TValue v;
UnicodeString vName = "b";
TFloat vValue = 2.0;
UnicodeString f = "sin(b)^2+cos(b)^2";
UnicodeString s = "";

TTranslator *FTranslator = new TTranslator();
TUtilities *Util = new TUtilities();

if (FTranslator->CheckSyntax(f)) {

	FTranslator->Add(vName, vValue);

	v = FTranslator->Calculate(f);

	s = Util->SafeToString(v);

	RichEditEvaluateResult->Text = f + " = " + s;

}

delete FTranslator;
delete Util;

}
//---------------------------------------------------------------------------

The execution:

Esecuzione

Of course, the modifications of the .hpp files are not the best solution, nor do they guarantee good working for all functions of the library; but my experience shows that the TMS Analytics & Physics library can work with C ++ Builder.

In my modest opinion, the problem derives from the choice of the names of the DRTE library files and from the way in which the delphi compiler (dcc32.exe and dcc64.exe) generates the namespaces in the .hpp files: for the Delphi code everything is OK; on the other side, the namespaces generated in the .hpp files are not "harmonized" to work simultaneously with each other and this confuses the C ++ Builder compiler.

TMS Analytics & Phusics Pack is advertised and sold as a product for Delphi. Hope this post helps extend it to the C ++ Builder as well.

1 Like