How to convert a Delphi variable of type sysutils.TEncoding into a .net variable of type System.Text.Encoding using Hydra


I need to pass from Delphi to .net the Information about which Encoding to use when writing a file.

On the Delphi side I have a var of type sysutils.TEncoding, e.g. containing TEncoding.UTF8
On .net side I need to passs a variable of ype System.Text.Encoding into a function.

What is the recommended way to do this using Hydra?



you can’t use delphi class on .NET side.
I can suggest to create a new enumeration and pass it instead of

thanks, I know, but System.Text.Encoding is a .net class, not a Delphi class.
It represents the same class as Delphi’s sysutils.TEncoding.

From your answer I conclude that everybody needing this mapping must implement it again by converting (Delphi side) sysutils.TEncoding into an own enum,
pass this enum via Hydra,
and recode this enum to System.Text.Encoding (.net side)?

Aren’t there any helper enums be REMObject which can be used?

you can use something like

TMyEncoding = (meUTF8, meUnicode ...);

this enum can be passed as byte : ord(meUTF8)

by other side, you can just pass UnicodeString and forget about any encoding…

I think a good option for this particular case would be to pass the encoding’s name, and reinstantiate then proper instance on the other side…