检查 Delphi WSDL 接口中是否存在值

Check if value is present in Delphi WSDL interface

我有一个 class 通过 Delphi 中的 "Import WSDL" 选项生成:

historyEntry = class(TRemotable)
private
    Fid: Integer;
    Fid_Specified: boolean;
    Ftemperature1: Double;
    Ftemperature1_Specified: boolean;
    Ftemperature2: Double;
    Ftemperature2_Specified: boolean;
    /// etc...

但是当没有temperature2时,简单的服务器不会发送tempera2标签。但是 historyEntry 对象 returns 0 对于那个温度 2 属性,并且由于温度可以为零,我无法将它与零进行比较以检查它是否有效。

有没有办法检查响应中是否真的有 temperature2 标签?

这里有几个选项,具体取决于上下文。 假设 Ftemperature1.. 等是简单的可空类型, 您可以:

  • 使用导入选项获得所需的行为:

DocWiki for import WSDL

Process nillable and optional elements

Check this option to make the WSDL importer generate relevant information about optional and nillable properties. This information is used by the SOAP runtime to allow certain properties be nil.

Use TXSString for simple nillable types

The WSDL standard allows simple types to be nil, in Delphi or NULL, in C++, while Delphi and C++ do not allow that. Check this option to make the WSDL importer overcome this limitation by using instances of wrapper classes.

DocWiki - Soap XSBuiltIns

这样,简单类型将被交换​​为复杂类型(如 TXSString),如果标签不存在则为 nil。 如果您可以修改 WSDL 本身,您可以

  • 对温度或您需要的任何标签使用复杂类型:

这会产生相同的结果

  • 使事情变得丑陋并初始化 Ftemperature... 在生成的 class 中使用一些奇异的值(例如 -300 摄氏度)