Empty string in Delphi marshalled as null string in .NET

Hello,

I have a hydra host in Delphi with a plugin in C# .NET.

I have defined the following interface:

Delphi:
IObject = interface(IHYCrossPlatformInterface)
function GetName: WideString; safecall;
procedure SetName(AName: WideString); safecall;
property Name: WideString read GetName write SetName;
end;

C#:
public interface IObject : RemObjects.Hydra.CrossPlatform.IHYCrossPlatformInterface
{
string Name { get; set; }
}

IObject is implemented in Delphi. When GetName returns an empty string I get null on the C# side. I don’t want the consumers of the C# interface to be forced to check for null strings all the time. Instead I want empty strings from Delphi to be empty string on the C# side as well.
What can I do achieve this behavior?

Regards,
Markus Samuelsson

Unfortunately this is not possible, nil is what Delphi passes to a .net. This is default behavior of the Widestring. And you won’t even be able to override this via custom marshaler, since it won’t process null.

All i can suggest is to create some sort of wrapper on the .net side for IObject that will control how string values is processed.