Thursday, May 5, 2011

How can I change SOAP element names to reserved words in Delphi?

I use this line to register a class with the Delphi registry for Soap elements:

RemClassRegistry.RegisterXSClass(ToHeader, ADD_URI);

In the Soap request message, I see this:

 <NS1:ToHeader> ... </NS1:ToHeader>

Is it possible to change the class registration so that it renders the element with a different name, like:

 <NS1:To> ... </NS1:To>

or is the only way to tweak the request stream?

To is a reserved word in Delphi, I can not rename the class to the element name 'To'.

From stackoverflow
  • Looks like that's what the third parameter is for. Try this:

    RemClassRegistry.RegisterXSClass(ToHeader, ADD_URI, 'To');
    

    As of Delphi 8, you can use reserved words for identifiers. Use & as an escape character, or use a fully qualified name:

    type
      &To = class;
    
    RemClassRegistry.RegisterXSClass(UnitName.To, Add_URI);
    
    mjustin : The & does help. I am not sure about the third parameter meaning, but have tried it already without visible effect. Many thanks for your input!

0 comments:

Post a Comment