Groups | Blog | Home
all groups > dotnet interop > january 2005 >

dotnet interop : c# and delphi


was19 NO[at]SPAM gmx.de
1/31/2005 8:09:23 AM
hi guys,

I need to use a function in a c# dll from delphi. I have written a
sample:

<code>
using System;
using System.Data;
using System.Runtime.InteropServices;

namespace DelphiTest
{
public interface IDelphiTest
{
void getparam(string IN_Param, out string OUT_Param, string IN_Ini,
out int OUT_int);
}

[ClassInterface(ClassInterfaceType.None)]
public class DelphiTestClass : IDelphiTest
{
public DelphiTestClass()
{

}

public void getparam(string IN_Param, out string OUT_Param, string
IN_Ini, out int OUT_int)
{
OUT_int=100;

OUT_Param= "hello";
}
}
}
</code>

I registered the dll with regasm. Now I created a *.tlb and then
imported it in my delphi 6 application. Then in delphi I created a
little function which creates a new instance of the c# class and then
calls the function getparam. It all works fine but there is no
function getparam. Why? What is wrong?

Frank Oquendo
1/31/2005 11:18:05 AM
[quoted text, click to view]

Just a guess: your class has no public interface so the client has no
idea what methods are available.

--
There are 10 kinds of people: those who understand binary and those who
Daniel Petersson, Cefalo
1/31/2005 9:55:05 PM
in this sample he does have a public interface.
My guess is that you are breaking some rule in
delphi that stops you from calling your methods.

Another possibility is to upgrade to the latest
delphi since it will have support for .net.

//daniel

[quoted text, click to view]
Matthias H.
1/31/2005 11:31:01 PM
Sorry but there is no option for me to update to delphi.NET.
It's right I have a public interface.
What rules? All I do is to import the *.tlb and then create an instance of
the class and call the function. Here is the code. The error is always "no
definition for getparam".

<code>
procedure TForm1.Button1Click(Sender: TObject);
var x: string;
y: integer;
MyClass: TDelphiTestClass;
begin
MyClass := TDelphiTestClass.Create(self);
MyClass.Connect();
MyClass.getparam('Test', x, 'Test2', y);
end;
Daniel Petersson, Cefalo
1/31/2005 11:35:01 PM
hi, Mattias

check the content of your tlb with oleview.exe and
verify that it contains what you expect it to contain.

You can modify how .net interfaces and classes are
exported to tlb using attributes, if the content of
the tlb isn't what you expect it to be you might be
able to modify it using attributes.

//daniel


[quoted text, click to view]
Matthias H.
2/1/2005 11:23:02 PM
I found it out but not with oleview. In the function I wanted to call I use
"out" to reference a parameter. There must be "ref" instead.
Eric
2/10/2005 1:24:56 PM
[quoted text, click to view]

And you should use early binding in Delphi - this is faster and
type-aware. Just import the .tlb file with Delphi's project menu. It
will create a .pas file that is similar to a proxy class in C#. You can
use the PAS file as a component to install in the VCL palette, or you
can dynamically create it.

AddThis Social Bookmark Button