Jump to content
bioman

MARSWebServer Compile error

Recommended Posts

[dcc32 Error] Server.Resources.pas(46): E2250 There is no overloaded version of 'TMARSResourceRegistry.RegisterResource<Server.Resources.THelloWorldResource>' that can be called with these arguments

 

An error occurs when compiling MARSWebServer, please tell me how to fix it.

Share this post


Link to post

Hi,

Do you mean the MARS\Demo\HelloWorld project?
If so, I just compiled it on Delphi 10.4.1. It runs without any problems.

 

 

If you mean the example MARS\Demos\MARSWebServer,

I always use the template from MARS\Demos\MARSTemplate for new projects.


Here the resource is registered without the anonymous method. The resource is created implicitly.

 

initialization
  TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>;
//  TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>(
//    function: TObject
//    begin
//      Result := THelloWorldResource.Create;
//    end
//  );

 

There is another difference with Server.Forms.Main.pas FormCreate

 

uses
  Web.HttpApp
  , MARS.Core.URL
  , MARS.Core.MessageBodyWriter, MARS.Core.MessageBodyWriters
  , MARS.Core.MessageBodyReader, MARS.Core.MessageBodyReaders
  , MARS.Utils.Parameters.IniFile, MARS.Core.RequestAndResponse.Interfaces
  ;
---  
  
procedure TMainForm.FormCreate(Sender: TObject);
begin
  // MARS-Curiosity Engine
  FEngine := TMARSEngine.Create;
  try
    FEngine.Parameters.LoadFromIniFile;
    FEngine.AddApplication('DefaultApp', '/default', ['Server.*']);
    PortNumberEdit.Text := FEngine.Port.ToString;

    FEngine.BeforeHandleRequest :=
      function (const AEngine: TMARSEngine;
        const AURL: TMARSURL; const ARequest: IMARSRequest; const AResponse: IMARSResponse;
        var Handled: Boolean
      ): Boolean
      begin
        Result := True;

        // skip favicon requests (browser)
        if SameText(AURL.Document, 'favicon.ico') then
        begin
          Result := False;
          Handled := True;
        end;

        // Handle CORS and PreFlight
        if SameText(ARequest.Method, 'OPTIONS') then
        begin
          Handled := True;
          Result := False;
        end;

      end;

    StartServerAction.Execute;
  except
    FreeAndNil(FEngine);
    raise;
  end;
end;

 

With these two changes I was able to compile and run the MARSWebServer project.
http://localhost:8080/rest/default/helloworld

In the resource, the path is set to c:\temp. Thus index.html is searched here.

 

Regards,

  Kostas

 

 

Edited by KostasR

Share this post


Link to post

Hi, sorry for the late.

Thanks for pointing it out the demos was not compiling.

Some demos are a bit outdated and I need to fix them according latest library changes.

I've just pushed an update for this (and some other demos) and it should now work out of the box.

More to come.

 

Sincerely,

Andrea

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×