简体   繁体   English

Delphi SOAP Client将项目添加到动态数组

[英]Delphi SOAP Client adding items to dynamic array

I'm currently developing a client for a SOAP service. 我目前正在开发SOAP服务的客户端。

The WSDL import works fine, but I'm facing the problem that I need to add items to a dynamic array. WSDL导入工作正常,但是我面临的问题是我需要向动态数组添加项目。

The declaration in delphi: 在delphi中的声明:

    Array_Of_attributWS = array of attributWS;

    dienstleistungWS = class(TRemotable)
      private
         [..]
      public
         [..]
      published
        property attributeWS: Array_Of_attributWS
         Index(IS_OPTN or IS_UNBD or IS_NLBL or IS_UNQL)read GetattributeWS
         write SetattributeWS stored attributeWS_Specified;

I want to add an item to attributeWS from an other unit. 我想从另一个单元将一个项目添加到attributeWS。 To add an item I use this code: 要添加项目,请使用以下代码:

    SetLength(dynArray, Length(dynArray)+1);
    dynArray[High(dynArray)] := item;

But it wont let me, I get the following error: E2197 Constant object cannot be passed as var parameter 但它不会让我遇到以下错误:E2197无法将常量对象作为var参数传递

Is there a way to add an item easy to the dynamic array? 有没有一种方法可以轻松地向动态数组添加项目? Or is there a way to cast the array to a list so that I can just do .Append(item)? 还是有一种方法可以将数组转换为列表,以便我可以执行.Append(item)?

Delphi Version XE6 Thanks! Delphi版本XE6谢谢!

If you check the SetattributeWS implementation you will see it simply gets your dynamic array as a const parameter, stores it and marks an internal boolean variable as true (indicating the parameter has been informed). 如果您检查SetattributeWS实现,您将看到它只是将动态数组作为const参数获取,存储它并将内部布尔变量标记为true(指示已通知该参数)。

The const part is the one that causes the E2197 error you are seeing. const部分是导致您看到的E2197错误的部分。

The best option is to use a local dynamic array variable of the same type and then: 最好的选择是使用相同类型的局部dynamic array变量,然后:

  1. set its length to the actual length of attributeWS + 1. 将其长度设置为attributeWS + 1的实际长度。
  2. copy the original items from attributeWS to the local variable, and then add the new item. 将原始项目从attributeWS复制到本地变量,然后添加新项目。
  3. assign this variable to the attributeWS property. 将此变量分配给attributeWS属性。

Actually, it would be better to not assign the dynamic array to the request property until you have it filled with all the necessary elements, but that may depend on your needs. 实际上,最好不要将动态数组分配给request属性,直到将其填充了所有必要的元素,但这可能取决于您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM