For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

"Hello World" application in Delphi?

Carl Olsen's picture
Forums: 

Anyone have an example of a "Hello World" application in Delphi?

I'm totally new to OpenCascade and want to evaluate how easy it might be to integrate into future projects. I searched the forums for "Delphi" and got a few hits, but nothing to really help me get started.

Anyone gone down this road before? Tips?

Thanks,

Carl.

PS: I typically use Delphi 2006, but I also have Delphi XE if that makes it any easier.

Paul Jimenez's picture

I use OpenCASCADE along with Delphi in an application, but it does not make use of it directly.

The core of the application is developed in C++, so there is no trick to use OpenCASCADE in there. All the C++ code is compiled into a DLL, and all objects that need to be manipulated from Delphi are exported through wrappers abusing Delphi's binary compatibility with C++. This way I can use the wrapper in Delphi (which I like to wrap again with an Interface, which will also give me reference counting), which ends up calling the methods of the C++ wrapper "directly" (through a virtual table), which then calls the methods on the C++ object, which makes use of OpenCASCADE in some way.

I guess you want to make use of OpenCASCADE directly, so you may need to start writing wrappers around it that you can somehow call from Delphi. The more objects and methods that you need to get access to, the more wrappers that you need to write.

If I recall correctly, someone did it using COM. That could be another option.

In any case, you will need to use a C++ compiler. Due to the nature of OpenCASCADE's binary release, your best options are VC++ or Intel C++. To use it with other C++ compilers you will need to re-compile OpenCASCADE with them (which needs some patching).

Carl Olsen's picture

This is the first time I have heard of doing things on the binary level, as you say "abusing Delphi's binary compatibility with C++". I assume what you refer to here is the fact that they share the same compiler, and that you are doing some kind of compiler magic to get around having to re-write a bunch of DLL header wrappers? Or is this just to be able to reference the objects?

Or is it that you mean that OCC comes as a DLL, and you simply wrote the necessary unit to interface with the DLL, like Delphi does with it's various units to interface with the Windows API?

Also, is the work you done available (Open source or for sale)?

Thanks!

Carl.

Paul Jimenez's picture

The compiler is not the same. The Delphi part uses Borland/Embarcadero/Whatever's compiler, and the C++ part used Microsoft's compiler at first and now Intel's.

I got many of the ideas from http://rvelthuis.de/articles/articles-cppobjs.html and some other documents in that website (and others), as well as some experimenting and debugging of code at the assembler level in both languages.

Converting C++ header files to Delphi is, in most cases, not possible. That trick only works nicely with C as Pascal and C have a lot more in common than Object-Pascal and C++.

There is no compiler magic being used. The abuse is in the form of how the Delphi compiler and C++ compilers (at least Microsoft's and Intel's) lay out objects in memory. By taking advantage of the common parts of the layout you can end up calling C++ objects directly from Delphi, but you still need to write the code that will guarantee that common layout. Most C++ code, OpenCASCADE included, will just not translate into Delphi right away.

The only way I can think of to be able to directly call C++ code from Delphi without those wrappers would be to write classes in Delphi that implement all details in assembler. I have not tried it myself, but it does not sound like a lot of fun.

The code is part of a commercial application, and, as I said, it does not provide direct access to OpenCASCADE.

I hope that link help you get an idea how to implement it.