Rodrigo
Rodrigo

Reputation: 33

Delphi and COM: Is it possible to pass a TClientDataset to a COM library as a parameter?

I have a Delphi VCL application that manipulates a TClientDataset object. I need to pass this object as a parameter to a custom COM library, also written in Delphi.

I have two questions: 1) Is this possible? 2) If so, how?

Upvotes: 3

Views: 223

Answers (1)

David Heffernan
David Heffernan

Reputation: 613282

No you cannot pass such an object. It is not a valid COM interop type. In fact you cannot even pass such an object between Delphi modules other than runtime packages.

The most obvious solutions are:

  • Wrap the object with a COM interface and pass that. The interface would have to expose methods to extract the data.
  • Serialize the data, for instance as JSON, and pass that as text. On the other side you would need to de-serialize.
  • Use the built in serialization capabilities as offered by the Data and XMLData properties of client data set.

The latter two serialization based options are probably simpler. But more costly in terms of memory. Using an interface requires more work to code, but may result in more efficient runtime performance.

Upvotes: 3

Related Questions