【问题标题】:Delphi SOAP Client adding items to dynamic arrayDelphi SOAP 客户端将项目添加到动态数组
【发布时间】:2015-05-18 08:35:41
【问题描述】:

我目前正在为 SOAP 服务开发客户端。

WSDL 导入工作正常,但我面临需要将项目添加到动态数组的问题。

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;

我想将一个项目从另一个单元添加到 attributeWS。 要添加一个项目,我使用以下代码:

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

但它不会让我,我收到以下错误: E2197 常量对象不能作为 var 参数传递

有没有一种方法可以轻松地将项目添加到动态数组中? 或者有没有办法将数组转换为列表,以便我可以执行 .Append(item)?

德尔福版XE6 谢谢!

【问题讨论】:

    标签: arrays delphi soap delphi-xe6


    【解决方案1】:

    如果您检查SetattributeWS 实现,您会看到它只是将您的动态数组 作为const 参数,将其存储并将内部布尔变量标记为真(表明该参数已告知)。

    const 部分是导致您看到的 E2197 错误的部分。

    最好的选择是使用相同类型的本地 dynamic array 变量,然后:

    1. 将其长度设置为attributeWS + 1的实际长度。
    2. attributeWS中的原始项复制到局部变量中,然后添加新项。
    3. 将此变量分配给attributeWS 属性。

    实际上,最好不要将动态数组分配给 request 属性,直到它填充了所有必要的元素,但这可能取决于您的需要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-24
      • 1970-01-01
      • 2011-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      相关资源
      最近更新 更多