1
votes

So I'm consuming SOAP services using Delphi, but struggling to set the value of an enum. Below is the enum declaration:

Extension = (pdf, xls, txt, xlsx, docx, doc, xml, png, jpg, gif);

This is declared in the unit Delphi imports once you import the WSDL. Now my app is using this unit, and I've tried below options, but to no avail.

Option 1: (Doesn't compile. Undeclared identifier: 'pdf')

uses SOAPAPI_Unit
type
   Extension = SOAPAPI_Unit.Extension;
....
procedure TForm1.Button2Click(Sender: TObject);
var
   Ext : Extension;
begin
   Document.Extension := pdf;
end;

Option 2: (Compiles, but I get a server error saying object ref not set)

uses SOAPAPI_Unit

....
procedure TForm1.Button2Click(Sender: TObject);
var
   Ext : SOAPAPI_Unit.Extension;
begin
   Document.Extension := Ext(0);
end;

Option 3 (Re-Declare the Enum in the main .pas file, but then I get Incompatible types: 'SOAPAPI_Unit.Extension' and 'formMain.Extension')

uses SOAPAPI_Unit
type
   Extension = (pdf, xls, txt, xlsx, docx, doc, xml, png, jpg, gif);
....
procedure TForm1.Button2Click(Sender: TObject);
var
   Ext : Extension;
begin
   Document.Extension := pdf;
end;

Option 4 (Compiles, but get object ref not set error from server)

uses SOAPAPI_Unit
....
procedure TForm1.Button2Click(Sender: TObject);
var
   Ext : Extension;
begin
   Document.Extension := Ext.pdf;
end;
1
Documentation recommends to use enumeration constant names that are not likely to conflict with other identifiers. If the identifiers are used for another purpose within the same scope, naming conflicts occur. Also use a more unique name for the enumeration type. - LU RD
I also find it hard to believe what you have written. I am a little sceptical that options 2 and 4 compile as written. If I had to guess I'd imagine that the enum is declared as a scoped enum, and that you just need to use the unit and refer to the values fully scoped. Document.Extension := Extension.pdf or is Extension clashes with something else then `Document.Extension := SOAPAPI_Unit.Extension.pdf. Attempting to re-declare the type is never going to work. Surely you appreciate why that is so. Don't guess. Try to understand. - David Heffernan

1 Answers

5
votes

The WSDL-Importer by default produces code with scoped enums active. This requires any enum to be preceded by its type. Without knowing the actual import file I guess this should work then:

uses SOAPAPI_Unit
....
procedure TForm1.Button2Click(Sender: TObject);
begin
   Document.Extension := Extension.pdf;
end;