tags:

views:

105

answers:

1

Hi.

I have a Delphi 2007 Program, which calls a Delphi 2010 DLL. The Program is big and not yet ported to 2010, so there is no way i can change this right now.

I use SimpleShareMem Unit to pass strings but also tried ShareMem with borlndmm.dll.

For one function i now pass a string from the Delphi 2007 programm to the dll (Therefore AnsiString). When debugging the dll, this AnsiString looks normal and can be viewed in the watch list. But if i do a simple think like

AnAnsiString := PassedAnsiString;

the variable AnAnsistring gets the value '???????'#0#0#0'???A', but PassedAnsiString is still readable in watchlist. Also a string append like

AnAnsiString := PassedAnsiString + NotPassedAnsiString;

uses '???????'#0#0#0'???A' as value.

Where is the problem? Is it a 2007 <-> 2010 issue? How to fix it? Thanks for help.

+6  A: 

This is probably because an encoding field that was added to ansistring in D2009. IOW the record (TAnsiRec) at negative offset of the ansistring pointer is different and shifted between unicode and non unicode Delphi's (ansistring changed too in unicode versions!)

I don't think there is a decent solution for this except dropping back to p(ansi)char level

Marco van de Voort
Indeed; DLL boundaries are only safe for types that are not Delphi specific. Sharing Delphi specific types across DLL boundaries only works when the underlying binary representations of these types are the same on either side of the boundary. Starting with Delphi 2009, the binary representation of AnsiString changed, so it is not binary compatible with previous Delphi versions any more.
Jeroen Pluimers
And if the memory manager is the same.
Marco van de Voort