如何使用WSDL中定义的自定义数组类型?

时间:2022-03-07 16:28:31

Trying to learn how to consume a WSDL in a Delphi 7 application. The WSDL I'm trying to consume has a custom array type.

试图学习如何在Delphi 7应用程序中使用WSDL。我正在尝试使用的WSDL具有自定义数组类型。

Pascal

ArrayOfSomething = array of Something;

How do I instantiate this array type?

如何实例化此数组类型?

Have tried:

Pascal

var 
    somethingList : ArrayOfSomething;
begin
    somethingList := ArrayOfSomething...
end;

The ... above means I'm looking for a method and not finding one. The normal way I would instantiate an object like:

......上面意味着我正在寻找一种方法而不是找到一种方法。我将实例化一个对象的正常方式:

Pascal

var 
    object : className;
begin
    object := className.Create;
end;

So you can see why I'd be trying to create the array in the same kind of way, even though it's not an object.

所以你可以看到为什么我会尝试以同样的方式创建数组,即使它不是一个对象。

Bear in mind, I'm cribbing C# code and trying to make it work in Pascal. The original C# is like:

请记住,我正在捣乱C#代码并试图让它在Pascal中运行。原来的C#就像:

C#

   List<Something> somethingList = new List<Something>();

And usage is like:

用法如下:

C#

   envelope.listField = somethingList.ToArray();

I've also tried this:

我也试过这个:

Pascal

   var
       somethingList : TList;
   begin
       somethingList := TList.Create;
   end;

Yeah, that works until I try to feed it into the envelope.

是的,这一直有效,直到我尝试将其送入信封。

Pascal

   envelope.listField := somethingList;

Envelope is expecting ArrayOfSomething not TList. Error is something like "Incompatible types, TList and ArrayOfSomething."

Envelope期待ArrayOfSomething不是TList。错误类似于“不兼容的类型,TList和ArrayOfSomething”。

2 个解决方案

#1


3  

An array of is a built-in type, it is not a class. To set its size, use SetLength(), e.g.

数组是内置类型,它不是类。要设置其大小,请使用SetLength(),例如

var
  Arr: ArrayOfSomething;
begin
  SetLength(Arr, 273);

Also note that it is not the same as a list, it is an array which has no built-in way to insert or delete values. You can read and change values, or change the size of the array, no more.

另请注意,它与列表不同,它是一个没有内置插入或删除值的方法的数组。您可以不再读取和更改值,或更改数组的大小。

If you want generics, like in C#, you'll have to use a higher version of Delphi than 7. I'm not sure, but I think they were introduced in Delphi 2010 or Delphi XE. I guess someone can update me on this (Update: David Heffernan told me it's version 2009)

如果你想要泛型,比如在C#中,你将不得不使用比7更高版本的Delphi。我不确定,但我认为它们是在Delphi 2010或Delphi XE中引入的。我想有人可以更新我(更新:David Heffernan告诉我它的版本是2009)

In these higher versions, you can also use TList<T>, which is probably what you want. Until then, you can use TList, which holds pointers (but is not directly usable in connection with WSDLs, so the contents may have to be moved to an array first). You may have to use New(), Dispose() and casts to use it.

在这些更高版本中,您还可以使用TList ,这可能是您想要的。在此之前,您可以使用TList,它保存指针(但不能直接与WSDL结合使用,因此可能必须先将内容移动到数组中)。您可能必须使用New(),Dispose()和强制转换才能使用它。

#2


1  

type
  ArrayOfSomething = array of Something;

This is a Delphi dynamic array. You initialize it with a call to SetLength:

这是一个Delphi动态数组。您通过调用SetLength初始化它:

SetLength(somethingList, 42);

You should take a read of the documentation for dynamic arrays to learn more.

您应该阅读动态数组的文档以了解更多信息。

#1


3  

An array of is a built-in type, it is not a class. To set its size, use SetLength(), e.g.

数组是内置类型,它不是类。要设置其大小,请使用SetLength(),例如

var
  Arr: ArrayOfSomething;
begin
  SetLength(Arr, 273);

Also note that it is not the same as a list, it is an array which has no built-in way to insert or delete values. You can read and change values, or change the size of the array, no more.

另请注意,它与列表不同,它是一个没有内置插入或删除值的方法的数组。您可以不再读取和更改值,或更改数组的大小。

If you want generics, like in C#, you'll have to use a higher version of Delphi than 7. I'm not sure, but I think they were introduced in Delphi 2010 or Delphi XE. I guess someone can update me on this (Update: David Heffernan told me it's version 2009)

如果你想要泛型,比如在C#中,你将不得不使用比7更高版本的Delphi。我不确定,但我认为它们是在Delphi 2010或Delphi XE中引入的。我想有人可以更新我(更新:David Heffernan告诉我它的版本是2009)

In these higher versions, you can also use TList<T>, which is probably what you want. Until then, you can use TList, which holds pointers (but is not directly usable in connection with WSDLs, so the contents may have to be moved to an array first). You may have to use New(), Dispose() and casts to use it.

在这些更高版本中,您还可以使用TList ,这可能是您想要的。在此之前,您可以使用TList,它保存指针(但不能直接与WSDL结合使用,因此可能必须先将内容移动到数组中)。您可能必须使用New(),Dispose()和强制转换才能使用它。

#2


1  

type
  ArrayOfSomething = array of Something;

This is a Delphi dynamic array. You initialize it with a call to SetLength:

这是一个Delphi动态数组。您通过调用SetLength初始化它:

SetLength(somethingList, 42);

You should take a read of the documentation for dynamic arrays to learn more.

您应该阅读动态数组的文档以了解更多信息。