Calling a C# .Net method that has ref String arguments from Delphi 7 -


Modified question:

We use the D7 to call the C # method in the COM object are doing. The C # method gives a widestring.

Is there any risk that .NET will collect widerstream returning from our feet while using it in our Pascal Code? If so, what are the options that we have to return a string safely to the C # com object?

In addition, is our last Delphi line submanine: = The proper way to release the COM object?

C # code

  [DispId (5)] Bull test (int verve 1, ref'in var2, ref string var3); Public Bull Test (Int. Verse 1, ref'in var2, riff string var3) {Bull results; If (var1 == 0) {var2 = 0; Var3 = "zero"; Result = true; } And {var2 = -1; Var3 = "one loan"; Result = false; } Return results; } Test code (var1: integer; var var2: integer; var var3);  

: Widestring): wordball; Devide 5;

Is there a risk to the Pascal code calling the COM object 3GC-ED?

  Process TForm1.Button1Click (Sender: Tubbed); Var Subman: Tsoubman; Var1: integer; Var2: integer; Var3: Widestring; Function Result: Boolean; Start Submen: = COTSubMan.Create; Var1: = 1; Function Rastalt: = Subman Test (Var 1, Hero 2, Verti3); // air var3 will be continuously in the code / or can we use it below or later before the trash can be collected by the net? ShowMessage (Bulletosaurt (function rasaltl, TRUE) + 'Var2 =' + IntToStr (Var2) + 'Var3 =' + Var3); Subman: = zero; // Is this the correct way to release the COM object? End;  

The code in your question is OK. COM marshaller handles the life span of two referee parameters for you, there is no danger to GC because the meaning of the parameters is clearly expressed. The objects that you work with Delphi side are not. Net objects and not such a GC.

In fact, GC is not a factor because it is COM; The fact is that on the other hand there is a pure object, the implemented COM server is neither here nor there. This is the responsibility of the .NET COM interop layer to present you a valid COM object.

Just to confirm, although the string was originally allocated in the C # COM object, var3 is safe to use in our Delphi button 1Click method?

Yes. Remember that this COM is standard for binary interop. You do not have to worry too much about the details. FWIW is a Delphi wrapper around a WideString COM BSTR type. This string type is a UTF-16 encoded string, the reference is counted, and the shared com allocates to the heap. The last thing is important. The fact is that the BSTR example is a shared comm stack, which allows them to be allocated in one module, and distributed in the other.

What is the proper way to release SubMan: = zero COM object?

Yes this is however in this code it is a bit useless because the local step is about to leave the field and you have the exact same effect as your zero assignment.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -