I need to store column values and access them from Delphi. These may be any primitive types - bool, integers and so on. I am accessing them by a property indexer or function, but I get an olevariant exception.
Is there any way to pass a variant from Delphi to the .Net? I can’t seem to call: public object GetValue(string key) or public void SetValue(string key, object value) from Delphi which imported as:
procedure SetValue(const key: WideString; const value: OleVariant); safecall;
function GetValue(const Key: WideString): OleVariant; safecall;
I have resorted to converting everything to string on the client side
Thanks
Yes, you can use variants, but it it is a little bit harder than other types, first of all you can only use OleVariant’s since they can hold only COM compatible types. Second problem is that you can pass OleVariant’s into methods only by reference.
So, for c# side this will look like:
object ReturnVariant(); void ParamVariant(ref object Data); object PropVariant { get; }
C# doesn’t have specific type for variants, and so they should be declared like System.Object. Our converter tool will convert object’s to OleVariant on the Delphi side. Please note that ParamVariant methods accepts parameter by reference. And that property can’t use setter since setter method works with parameters passed by value.
The same for Delphi side will look like:
function ReturnVariant: OleVariant; safecall; procedure ParamVariant(var Data: OleVariant); safecall; function get_PropVariant: OleVariant; safecall; property PropVariant: OleVariant read get_PropVariant;