#1 2014-12-08 15:50:39

Wim314
Member
Registered: 2014-12-03
Posts: 13

Error compiling Mustache generated CrossPlatform Client-wrapper

We have a TSQLRestServerDB instance running, exposed via a TSQLHttpServer instance.

On the RESTServer instance there's an interface registered with some functions and procedures. These can be called without any problem from a VCL mORMot client.
Problem though, is the server generated (Mustache) CrossPlatform client wrapper. This code can't be compiled if it's not adapted.

Extract of the code on the server:

  TDTOActivePatient = packed record
    Id: Integer;
    FullName: String;
    Gender: TGender;
  end;

  TDTOActivePatientDynArray = array of TDTOActivePatient;

  IPatientAdministration = interface(IInvokable)
    ['{80091C16-DBA2-494F-A375-28ED102338D9}']
    function GetActivePatients: TDTOActivePatientDynArray;
    procedure CreatePatient(var thePatient: TSQLPatient);
  end;



Extract of the generated client code:

  TServicePatientAdministration = class(TServiceClientAbstract,IPatientAdministration)
  public
    constructor Create(aClient: TSQLRestClientURI); override;
    function GetActivePatients(): TDTOActivePatientDynArray;
    procedure CreatePatient(var thePatient: TSQLPatient);
  end;

  /// map "Patient" table
  TSQLPatient = class(TSQLRecord)
  protected
    fFirstName: string;
    fFamilyName: string;
    fGender: TGender;
    fIsActive: boolean;
  published
    property FirstName: string index 50 read fFirstName write fFirstName;
    property FamilyName: string index 50 read fFamilyName write fFamilyName;
    property Gender: TGender read fGender write fGender;
    property IsActive: boolean read fIsActive write fIsActive;
  end;

  function TServicePatientAdministration.GetActivePatients(): TDTOActivePatientDynArray;
  var res: TVariantDynArray;
  begin
    fClient.CallRemoteService(self,'GetActivePatients',1, // raise EServiceException on error
      [],res);
    Result := res[0];
  end;

  procedure TServicePatientAdministration.CreatePatient(var thePatient: TSQLPatient);
  var res: TVariantDynArray;
  begin
    fClient.CallRemoteService(self,'CreatePatient',1, // raise EServiceException on error
      [thePatient],res);
    thePatient := res[0];
  end;

To be able to compile the generated code we had to make some changes, f.i. define:

  TDTOActivePatientDynArray = Variant;
  TSQLPatient = class;

The first, TDTOActivePatientDynArray, a return parameter wasn't defined.
The second one, TSQLPatient was defined, but already used/called before it was declared in the unit. Could also have moved the TSQLPatient definition.

With these changes the 'GetActivePatients' function works. The 'CreatePatient' procedure still does not compile (generated code) as the types don't match.

Any ideas how to take it from here? Is there anyone that can point us to a sample in which SOA services are called from a FMX client (CrossPlatform) and that use f.i. a TSQLRecord instance as a parameter?

Thnx

Offline

#2 2014-12-09 14:00:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Error compiling Mustache generated CrossPlatform Client-wrapper

Hello Wim,

See http://synopse.info/fossil/info/06c19af441 to ensure ORM classes are defined before SOA interfaces for cross-platform client templates.

I'm still adding support of dynamic arrays DTOs.
In fact dynamic arrays are supported within records, but not directly as dynamic arrays.

There is also in fact a problem with TSQLRecord parameters: they are not handled by the Mustache template yet: they should be converted to/from variants.

Stay tuned!

Offline

#3 2014-12-10 21:38:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Error compiling Mustache generated CrossPlatform Client-wrapper

I've finished a huge refactoring of the mORMot wrapper generation code.
In practice, code was difficult to follow and let evolve.
So now all generation will take place in mORMotWrappers.pas so would be much easier to maintain.

I've also enhanced dynamic arrays and TSQLRecord support in generated code.
See http://synopse.info/fossil/timeline

Your feedback is welcome!

Offline

#4 2014-12-11 10:02:19

Wim314
Member
Registered: 2014-12-03
Posts: 13

Re: Error compiling Mustache generated CrossPlatform Client-wrapper

Thnx, first test looks very promising.
We'll keep you posted.

Last edited by Wim314 (2014-12-11 10:02:46)

Offline

Board footer

Powered by FluxBB