I am trying to create a C# DLL which could be used in Delphi. But I am getting an error at implementation:
My C# code is follows:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Json;
using System.Text;
namespace WebServiceHelper
{
[Guid("4762FAC0-9CCC-4F9B-B1CD-E8C15FF13A02")]
[ComVisible(true)]
public interface IDataSync
{
int Add(int a, int b);
}
[Guid("DE887257-1A62-420C-BEED-BC6A73DF8F9D")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class DataSync : IDataSync
{
public int Add(int a, int b)
{
return a + b;
}
}
}
I have also checked the Registry for COM interop option in C# project:
Post build, I registered the DLL using regasm:
regasm.exe D:\path\WebServiceHelper.dll /tlb: "WebServiceHelper.tlb" /codebase
In Import Type Library, the .tlb or .dll file is not visible, so I added it from the Add option:
Delphi Code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses WebServiceHelper_TLB;
procedure TForm1.Button1Click(Sender: TObject);
var helper1 : TDataSync;
begin
helper1:= TDataSync.Create(Self);
writeln(helper1.Add(5,5));
Edit3.Text := InttoStr(helper1.Add(5,5));
end;
end.


