Pass SqlConnection from C# host to Delphi plugin

(Paul Sjoerdsma) #1


I am trying to figure out if this is at all possible.
What I want to achieve is the following
1- Open a SqlConnection in C#
2- Insert/Update/Delete some data
3- Handover control to teh Delphi Plugin, which should use the same SqlConnection
4- The Delphi Plugin can do some work
5-Close the SqlConnection

There is a basic requirement:
If any error occurs either in the host or in the plugin a rollback should occur. So all work done should be undone in that case. So the plugin will return either an exception or an errorcode so that the calling process can perform a rollback on the active SqlConnection

So the question is, can I pass an active/open SqlConnection with an associated active transaction from a C# host to a Delphi Plugin and be able to use that same connection?


(EvgenyK) #2

you can’t pass C# object to Delphi as is, but you can create an interface and wrapper that will translate interface methods to SqlConnection.

(Paul Sjoerdsma) #3

Do you have a quick example


(EvgenyK) #4

you can review the Delphi WPF sample.
it has interface (IVisualizerControl) and wrapper (VisualizerWrapper) that allows to manipulate WPF control from Delphi