[fpc-pascal] Strings and objects crossing dll boundaries

kyan alfasud.ti at gmail.com
Thu Jun 14 11:59:09 CEST 2012

Hello all,

A couple of questions regarding handling of strings, dynamic arrays
and objects -especially exceptions- when writing programs that use
shared libraries (.dll, .so).

In Delphi we have the option of either using packages to ensure that
there is only one instance of the memory allocator or use ShareMem.pas
that installs a memory allocator that can handle memory allocations
across libraries. Given that in FPC/Lazarus there are no "packages" in
the Delphi sense what is the equivalent of ShareMem.pas? Is it

Regarding objects, in Delphi an object cannot safely cross dll
boundaries because separate class record(s) for it exist in each
executable file. OK, actually it can if one is certain that the class
records compiled in each executable are identical. But if an exception
crosses dll boundaries then you are in trouble, because the operator
"is" does not work due to the class pointer that points to another
Exception class record than the one known by the handling executable.
The best way to solve this is to put the class Exception at least
inside a package that all executables use so at least "is" will work
for Exception. Is there a way to handle this problem in FPC that does
not have packages?



More information about the fpc-pascal mailing list