Search code examples
delphirestenumsdatasnap

Delphi Enumerated types in REST Server


I have a Delphi XE5 (Update 2) program created using the IDE's standard 'File | New | Other | DataSnap Server| DataSnap REST Application' Wizard.

I cannot seem to get enumerated types to work when used as a parameter of a server method. All other server methods work such as those that take other classes as parameters, strings etc. When I try to call the method that has an enum parameter from a web browser, I get the error message 'Project Project1.exe raised exception class TDBXError with message 'TServerMethods1.EnumString method not found in the server method list'.

Here's my basic test code:

type
{$METHODINFO ON}
  TMyEnum=(meOne, meTwo);

  TServerMethods1 = class(TDataModule)
  private
    { Private declarations }
  public
    { Public declarations }
    function EchoString(Value: string): string;
    function ReverseString(Value: string): string;
    function EnumString(const AEnum: TMyEnum): string;
  end;
{$METHODINFO OFF}

However, what is weird is that I can get enumerated types to work if they are contained within another class and then this class is passed a parameter to my method. If I change the enum parameter to be an integer, then this work, but I don't really want to do that.


Solution

  • Using enumerations is not supported as method arguments. If Datasnap finds an argument type on a method that it doesn't support it will act as if the method doesn't exist, which causes the error you see.

    For a list of supported argument types, look at the TDSServerClass documentation:

    http://docwiki.embarcadero.com/Libraries/XE7/en/Datasnap.DSServer.TDSServerClass