delphi - 使用 JCL 和 CLR 返回复杂类型(类、类数组)

标签 delphi clr delphi-xe jedi-code-library

我首先引用了this question开始,但在尝试返回 时遇到了障碍类(class) 类数组在 Delphi XE 中使用 .NET 程序集。

考虑以下:

//C#
[ComVisible(true)]
public class Person {
    public int Id;
    public string Name;
}

public class SomeClass 
{
    public SomeClass() {}        

    public Person[] GetPersons()
    {
        //some code
    }
}

//Delphi
type TPerson = class
  Id : Integer;
  Name : string;
end;

如何理解从 GetPersons() 返回的数据?我可以分配给 array of TPerson在德尔福?

最佳答案

你不能,至少不能那样。 Delphi 和.NET 有不同的对象模型和不同的字符串类型,它们彼此不兼容。如果您想在 .NET 和 Delphi 模块之间传递对象,最好的方法可能是使用 COM。

关于delphi - 使用 JCL 和 CLR 返回复杂类型(类、类数组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4161566/

相关文章:

delphi - sndPlaySound 或 PlaySound on KeyPress - 播放键盘声音

c# - CLR运行时生成编译

clr - 签名 .NET 程序集 : Does this protect my assembly from tampering really?

sql-server-2008-r2 - SQL71501 : Trigger: [dbo]. [TriggerName] 具有对对象 [dbo].[TableName] 的未解析引用

delphi - 编译器警告 "return value might be undefined"

delphi - PaintTo 不适用于我的组件

delphi - 警告。 Delphi 7、Infopower 4000 中的重复资源

delphi - 我应该转向新的 Delphi XE Starter 吗?

delphi - 我需要 TThreads 吗?如果可以,我可以暂停、恢复和停止它们吗?

delphi - 服务中的 CreateProcessWithLogonw 返回代码 5 : access denied