Exporting lots of classes rapidly

Hello,

In one of our applications, we have a (rather) large code base in Delphi whose non visual part should be made available to .Net based code.
As we are already using Hydra to import .Net visual components in another program, we thought of doing the reverse situation with Hydra.
So I went on and created a plugin project, added the controller, and the plugin class.
But how do I “publish” existing classes ?
Can it be done by adding special attributes to the preexisting classes ?

I could not find anything obvious in the documentation, but maybe I did not look in the right place.

Hi,

You can’t consume Delphi classes as is in .NET code.
however you can create COM interfaces that can be consumed by .NET code.

See how to implemented IHYCrossPlatformModuleController interface:

  IHYCrossPlatformModuleController = interface(IHYCrossPlatformInterface)
  ['{65ad4b74-55e9-4a3e-9cde-3730a939c075}']
...
    function get_Host: IHYCrossPlatformHost; safecall;
    procedure set_Host(const value: IHYCrossPlatformHost); safecall;
    property Host: IHYCrossPlatformHost read get_Host write set_Host;
  end;
  THYCrossPlatformModuleController = class(TDataModule, IHYCrossPlatformModuleController, IHYCrossPlatformModule)
...
    function get_Host: IHYCrossPlatformHost; virtual; safecall;
    procedure set_Host(const value: IHYCrossPlatformHost); virtual; safecall;
...
  end;

In the similar way, you can pass interface that can be used by .NET side for communication with Delphi object

Yes, I know how to consume a .Net class in Delphi with Hydra.
But I want to do the reverse and I can’t find good explanations for this. In particular, I’m looking at ways to get this (semi)automated because I have lots of classes and do not want to manually write a wrapper class for each and every one of them.

if they are descendants of TROComplexType, you can easily serialize them and deserialize on .NET side… otherwise you should create interfaces …

Well, yes, pretty much like with RO SDK.
But creating 200 interfaces manually, along with the implementation classes is way too cumbersome, I was really looking for something like the Code First approach where it is as simple as adding an attribute to an existing class.

Hi,

you can try to use

procedure ReadObjectFromSerializer(const ASerializer: TROSerializer; anObject : TObject);
procedure WriteObjectToSerializer(const ASerializer: TROSerializer; anObject: TObject);

not sure about similar methods in .NET …
at least you can get XML/JSON stream that can be read on .NET side