Indexed properties

I am using Hydra to allow a client app written in Delphi to use .NET assemblies written in C#.

I was pleased to find that a property defined in one of the C# classes is exposed as a property at the Delphi level. Very nice!

However, indexers defined in the C# classes are exposed as get_Item, rather than as indexed properties in Delphi. Is it possible to arrange the code so that an indexed property is declared in the import file created by Hydra?

Thanks

  • rick cameron
    Softrak

Unfortunately our converter doesn’t work with indexed properties, so if you still want to use them you will need to manually change imported Delphi unit, for example:

c# property:

string this[int Index] { get; set; }

will be converted to:

    function get_Item(const Index: LongInt): WideString; safecall;
    procedure set_Item(const Index: LongInt; const value: WideString); safecall;

To make indexed property in Delphi, change it to:

    function get_Item(Index: LongInt): WideString; safecall;
    procedure set_Item(Index: LongInt; const value: WideString); safecall;

    property Item[Index: LongInt]: WideString read get_Item write set_Item;

And now this should work as expected:

    ShowMessage(MyInterface.Item[325]);
    MyInterface.Item[245] := 'The Value';

Thanks, ejay.

At this stage I’m regenerating the Import unit quite frequently. Does Delphi provide a mechanism to extend a class in another source file, so that I could put the extra function declaration there & avoid having it wiped out when I regenerate the Import unit?

  • rick

@rickc_softrak, unfortunately no, Delphi doesn’t have allow ‘partial’ classes/interfaces. And class helpers can only be used on class and record.