【问题标题】:Returning complex types (Classes, Arrays of Classes) using JCL and CLR使用 JCL 和 CLR 返回复杂类型(类、类数组)
【发布时间】:2010-11-12 04:18:21
【问题描述】:

我首先引用 this question 开始,但在尝试使用 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() 返回的数据,我可以在 Delphi 中将其分配给 array of TPerson

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • +1 表示“Delphi 和 .NET 有不同的对象模型和不同的字符串类型,彼此不兼容”
    • 您能否提供示例链接?我没有任何使用 COM 的经验。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2013-05-26
    • 2021-12-25
    • 2017-02-06
    • 1970-01-01
    • 2018-06-26
    相关资源
    最近更新 更多