PowerBuilder(作为 COM)中的 .NET dll 列表问题
所有,我正在尝试访问使用 PowerBuilder 10 注册为 COM 对象的 .NET dll。我不断遇到 .NET 对象返回列表的问题。
我构建了一个非常简单的类来证明概念,并更好地解释我所遇到的情况。请参见下文:
.NET:
public class ListsArrays
{
public int[] GetArray()
{
int[] array = new int[3];
array[0] = 1;
array[1] = 10;
array[2] = 100;
return array;
}
public List<int> GetList()
{
List<int> list = new List<int>();
list.Add(3);
list.Add(33);
list.Add(333);
return list;
}
public int[] GetListArray()
{
List<int> list = new List<int>();
list.Add(3);
list.Add(33);
list.Add(333);
return list.ToArray();
}
}
PowerBuilder:
Integer ls_array[]
Integer obj_return, ID, netVal
String FullName
OleObject lo_dotnetobject
OleObject lo_Value
lo_Value = Create OleObject
lo_dotnetobject = Create OleObject
obj_return = lo_dotnetobject.ConnectToNewObject("XXX.ListsArrays")
//This is the tricky part
ls_array = lo_dotnetobject.GetArray() // WORKS (1)
ls_array = lo_dotnetobject.GetList().ToArray() // DOES NOT WORK (2)
lo_dotnetobject.GetList().CopyTo(ls_array) // DOES NOT WORK (3)
ls_array = lo_dotnetobject.GetListArray() // WORKS (4)
对于“不起作用”的每个部分,我都会收到此错误消息:
“在行表达式中使用没有返回值的函数/事件”
显然,我可以换行我的 .NET 程序集,并为每个列表返回一个数组,但我希望能够在 PowerBuilder 端处理列表而不包装 .NET。有人有什么想法吗? (4) 有效而 (2) 无效这一事实让我有点抓狂。
谢谢。
All, I am trying to access a .NET dll registered as a COM Object with PowerBuilder 10. I keep running into problems where .NET objects return lists.
I have built out a very simple class for a proof of concept, and to better explain what I am encountering. See below:
.NET:
public class ListsArrays
{
public int[] GetArray()
{
int[] array = new int[3];
array[0] = 1;
array[1] = 10;
array[2] = 100;
return array;
}
public List<int> GetList()
{
List<int> list = new List<int>();
list.Add(3);
list.Add(33);
list.Add(333);
return list;
}
public int[] GetListArray()
{
List<int> list = new List<int>();
list.Add(3);
list.Add(33);
list.Add(333);
return list.ToArray();
}
}
PowerBuilder:
Integer ls_array[]
Integer obj_return, ID, netVal
String FullName
OleObject lo_dotnetobject
OleObject lo_Value
lo_Value = Create OleObject
lo_dotnetobject = Create OleObject
obj_return = lo_dotnetobject.ConnectToNewObject("XXX.ListsArrays")
//This is the tricky part
ls_array = lo_dotnetobject.GetArray() // WORKS (1)
ls_array = lo_dotnetobject.GetList().ToArray() // DOES NOT WORK (2)
lo_dotnetobject.GetList().CopyTo(ls_array) // DOES NOT WORK (3)
ls_array = lo_dotnetobject.GetListArray() // WORKS (4)
For each part that “DOES NOT WORK” I receive this error message:
“Function/event with no return value used in expression at line”
Obviously, I could just wrap my .NET assembly, and return an array for every list, but I would like to be able to handle lists on the PowerBuilder side without wrapping the .NET. Does anyone have any ideas? The fact that (4) works and (2) doesn’t work drives me kind of nuts.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 Powerbuilder 已经有 10 多年了,但我想说
List
不起作用,只是因为它是一个通用列表,我认为它无法正确映射到COM 数组 - 这可以解释为什么 1 和 4 有效,但没有其他作用。您可以使用简单数组而不是通用列表吗?It's been more than 10 years since I worked with Powerbuilder, but I would say that
List<int>
would not work simply because it is a generic list which I don't think can be correctly mapped to a COM array - that would explain why 1 and 4 works but nothing else. Can you work with simple arrays instead of generic lists?我以前每天在向 COM 公开丰富的 .NET API 时都会处理这个问题。 COM 不理解泛型,但不要让它减慢您的速度 - 技巧是将泛型列表公开为
List
已公开的非泛型、com 可见的基本类型,如 IList。将 GetList 返回类型更改为 IList,重建/注册,并确保 Powerbuilder 看到您的固定类型库,一切都应该很好。I used to deal with this every day when exposing rich .NET APIs to COM. COM doesn't understand generics, but don't let that slow you down- the trick is to expose the generic list as a non-generic, com-visible base type that
List<int>
already exposes, like IList. Change your GetList return type to IList, rebuild/register, and make sure that Powerbuilder sees your fixed typelib, and all should be well.