用于 Delphi 编程的 .Net 运行时库

问题描述 投票:0回答:1

我使用 Delphi 的 .Net 运行时库并在我的项目中成功加载程序集 (C#)。仅当尝试从汇编中获取字符串结果时,我才会遇到问题。 我的 C# 代码是:

[DispId(0)]
public int Add(int a, int b)
{
  return a + b;
}
[DispId(1)]
public string GetProtectedID(string InString)
{
  return "12345";
}

我的德尔福代码是:

_SISign = dispinterface
['{AAFE8566-37E1-485B-9727-7223F7731F19}']
  function Add(a, b : Integer) : Integer; dispid 0;
  function GetProtectedID(InString: String): String; dispid 1;
  end;

var
  oSISign : _SISign;
begin
  WriteLn(oSISign.Add(10, 20));
  WriteLn(oSISign.GetProtectedID('SomeText'));
end;

第一行返回 30,第二行什么也没有。

c# .net delphi
1个回答
-2
投票

我现在找到了一些解决方案。

在 C# 中,我更改:

public integer GetProtectedID(string InString, out string OutString)
{
  OutString = "Result HERE";
  return 0;
}

在Delphi编程中,我改为:

_SIXmlSign = dispinterface
    ['{4a674fd3-244f-4802-9b1d-9eb0b0efb282}']
  function GetProtectedID(InString: String; var OutString: String): Integer; dispid 1;
end;

现在代码可以运行了

© www.soinside.com 2019 - 2024. All rights reserved.