#1 2016-08-08 11:59:51

amsdev
Member
Registered: 2011-09-16
Posts: 23

mORMot in C++ Builder: almost works but need help !

Hello,

I found mORMot few years ago and want to use it very much but... My project written in C++Builder :-( I and other peoples on this forum try to compile it for BCB with no success because of heavy Object usage wich is not supported in C++.
But I try to do it with every RAD Studio release. Few days ago I make another attempt with latest mORMot build and C++Builder Berlin and almost make it works ! At least I can generate .hpp and .o files, rewrite 01 - In Memory ORM sample in C++ and compile/link/run it in BCB ! And it's paritally works (successfuly save to TSQLRestStorageInMemory but AV on retreive, possible due to constructors problem, see bellow).

This changes in mORMot needed for base BCB compatibility:

SynBidirSock.pas: change TWebSocketProcessSettings from Object to Record
SynZipFiles.pas: change TSynCompressionAlgos, TBlobData, TMemoryMap from Object to Record.
mORMot.pas: change TClassInstance, TSQLRibbonTabParameters, TSynMonitorUsageID, TServicesPublishedInterfaces, TServicesPublishedInterfaces from Object to Record.

This changes NOT produce any bugs (TestSQL3 works same as unmodified version) but allow to compile mORMot files with "Generate C++ .objs, headers, namespaces, export" option. Of course generated .hpp files not compiles becase SynWinSock.pas and mORMotService.pas contains lot of Constants wich conflict with winsock.h, winbase.h, etc, but it's can be easy fiexed by comment out or add lots of {$EXTERNALSYM} to mORMot sources. There is also some issues with IInvokable and _di_IInvokable but it's can be easy fixed to.

The biggest problem in BCB is TSQLRecord constructors: in C++ constructors can't have different names like in Pascal. For example this TSQLRecord constructors:

constructor CreateFrom(const JSONRecord: RawUTF8); overload;
constructor CreateAndFillPrepare(const aJSON: RawUTF8); overload;

Will be translated to C++ as:

__fastcall TSQLRecord(const Syncommons::RawUTF8 JSONRecord);
__fastcall TSQLRecord(const Syncommons::RawUTF8 aJSON);

This is not valid in C++ because overloaded constructors can't have same parameters and their types !

Same problem with SynZipFiles.TZipCompressor:

constructor Create(outStream: TStream; CompressionLevel: Integer; Algorithm: integer=0);
constructor CreateAsBlobData(outStream: TStream; CompressionLevel: Integer; Algorithm: integer=0);

Accoridng to this arcticle: http://community.embarcadero.com/blogs/ … lder-22631

"So, apart from what the JVCL pages describe, you should also avoid using constructors with the same signature but differing in name. It is best if you simply do not use any other constructor name than Create. If you need more than one, be sure to use the overload directive."

But it's not possible to just rename all TSQLRecord constructors to .Create because it's break entire framwork and documentation :-(

Maybe Arnaud or others can suggest some workaround ? This issues probably not fatal and if fixed mORMot can be also used in C++Builder !

Offline

Board footer

Powered by FluxBB