#1 2015-01-29 13:15:24

aivanov
Member
Registered: 2014-06-30
Posts: 6

Small change proposal for CrossPlatform

Hi,

I am not aware of another way of proposing changes, so please don't flame me. This is a minor thing anyway, so I'll put it here because it's easy to explain.

Reason: allow passing an extra parameter to the mORMotClient.GetClient function - the root of the server. This would allow the client exe to connect to any server

// Modified file: CrossPlatform\templates\CrossPlatform.pas.mustache

interface

function GetModel(aServerRoot: String): TSQLModel;

function GetClient(const aServerAddress{{#authClass}}, aUserName,aPassword{{/authClass}}: string;
  aServerPort: integer=SERVER_PORT; aServerRoot: String = '{{root}}'): TSQLRestClientHTTP;

implementation

function GetModel(aServerRoot: String): TSQLModel;
begin
  result := TSQLModel.Create([{{#orm}}{{className}}{{comma}}{{/orm}}],aServerRoot);
end;

function GetClient(const aServerAddress{{#authClass}}, aUserName,aPassword{{/authClass}}: string;
  aServerPort: integer; aServerRoot: String): TSQLRestClientHTTP;
begin
  result := TSQLRestClientHTTP.Create(aServerAddress,aServerPort,GetModel(aServerRoot),true); // aOwnModel=true
  try
    if (not result.Connect) or (result.ServerTimeStamp=0) then
      raise ERestException.CreateFmt('Impossible to connect to %s:%d/%s server',
        [aServerAddress,aServerPort,aServerRoot]);
{{#authClass}}
    if not result.SetUser({{.}},aUserName,aPassword) then 
      raise ERestException.CreateFmt('%s:%d/%s server rejected "%s" credentials',
        [aServerAddress,aServerPort,aServerRoot,aUserName]);
{{/authClass}}
  except
    result.Free;
    raise;
  end;
end;

Cheers,
Albert

Offline

#2 2015-01-29 13:54:15

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

Re: Small change proposal for CrossPlatform

Good idea.

Should be implemented - for both Delphi CrossPlatform and SmartMobileStudio - by http://synopse.info/fossil/info/8adc764592

Thanks for the feedback.

Offline

#3 2015-01-29 15:46:44

aivanov
Member
Registered: 2014-06-30
Posts: 6

Re: Small change proposal for CrossPlatform

I'm happy to hear, thank you Arnaud.

Is this the correct way to propose this kind of minor changes?

I am sure there will be more to come ...

Offline

#4 2015-01-29 16:55:53

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

Re: Small change proposal for CrossPlatform

Either you can fork the project on http://github.com/synopse/mORMot
and notify any pending pull request by email, so that I would not miss it.

Or you can just email me the modified files as .zip, since you have my email address.
wink

Offline

#5 2015-02-27 11:38:06

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Small change proposal for CrossPlatform

This minor change will affect SmartMobileStudio, it will generate the following syntax error:
const parameter cannot have a default value

// This works in SMS
procedure test;
const aRoot: string=SERVER_ROOT;
begin

end;

// This does not work
procedure test(const aRoot: string=SERVER_ROOT);
begin

end;

Offline

#6 2015-02-27 11:43:34

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

Re: Small change proposal for CrossPlatform

I guess http://synopse.info/fossil/info/ca1bad49bd would fix it.

Thanks for the feedback.

Offline

#7 2015-03-04 18:32:27

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Small change proposal for CrossPlatform

Thanks, this fix worked out for me.

It seems that there's an issue when you use the type source Wrapper: "TServiceCustomAnswer";
for instance:
    function TServ.MyMethod1: TServiceCustomAnswer;
    function TServ.MyMethod2: TServiceCustomAnswer;

SMS wrapper will generate an incomplete record type.

a) Syntax Error: Name expected [line: 30, column: 4, file: mORMotClient]

type // define some record types, used as properties below
   = record
  end;

   = record
  end;

b) Syntax Error: Unknown name "TServiceCustomAnswer" [line: 83, column: 36, file: mORMotClient]

procedure MyMethod1(
      onSuccess: procedure(Result: TServiceCustomAnswer); onError: TSQLRestEvent);
    function _MyMethod1(): TServiceCustomAnswer;

c) Syntax Error: Type expected [line: 115, column: 42, file: mORMotClient]

// publish some low-level helpers for variant conversion
// - used internally: you should not need those functions in your end-user code
function Variant2(const Value: variant): ;
function 2Variant(const Value: ): variant;
function Variant2(const Value: variant): ;
function 2Variant(const Value: ): variant;


{ Some helpers for record types:
  due to potential obfuscation of generated JavaScript, we can't assume
  that the JSON used for transmission would match record fields naming }

function Variant2(const Value: variant): ;
begin
end;

function 2Variant(const Value: ): variant;
begin
  result := new JObject;
end;

function Variant2(const Value: variant): ;
begin
end;

function 2Variant(const Value: ): variant;
begin
  result := new JObject;
end;

d) Syntax Error: Number, point or exponent expected (found "V") [line: 116, column: 11, file: mORMotClient]
function 2Variant(const Value: ): variant;

Offline

#8 2015-03-04 19:00:02

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

Re: Small change proposal for CrossPlatform

Could you try  http://synopse.info/fossil/info/6f133748a8 ?
Now those methods would expect a THttpBody type as return value, containing the raw content from the server.

Thanks for the feedback.

Offline

#9 2015-04-18 23:02:43

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Small change proposal for CrossPlatform

The new SmartMobileStudio release 2.2.03985 will affect proj. 27 & 29:

27 - CrossPlatform Clients\SmartMobileStudio
Syntax Error: Incompatible types: "TSQLFieldBit" and "Integer" [line: 1270, column: 32, file: SynCrossPlatformREST]
Syntax Error: Incompatible types: Cannot assign "Integer" to "TSQLFieldBit" [line: 1525, column: 21, file: SynCrossPlatformREST]
Syntax Error: There is no accessible member with name "AsDateTime" [line: 778, column: 8, file: SynCrossPlatformSpecific]

const
  /// the first field in TSQLFieldBits is always ID/RowID
   ID_SQLFIELD: TSQLFieldBit = 0;
//ID_SQLFIELD: TSQLFieldBit = TSQLFieldBit(0);

29 - SmartMobileStudio Client
Compilation failed [Failed to build project: Internal error. Code-generator threw exception EVariantInvalidOpError with message Invalid variant operation] error

Tip: To open project at SmartMS2.2, firstly, open project 29 (with SMS old version 2.1), and "Make Project as Internal".
------
[INFO] Building project 'WebForm'...
[INFO] Compiling...
[ERROR] Compilation failed! Error(s): 2
Syntax Error: Argument 0 expects type "TTextAlign" instead of "Integer" [line: 5, column: 10, file: LoginForm:impl]
Syntax Error: There is no accessible member with name "AsDateTime" [line: 37, column: 7, file: SmartTests]
[INFO] Generating JavaScript successful []
------
JDateHelper was removed from unit W3C.Date:

JDateHelper = helper for JDate
    private
      function GetAsDateTime : TDateTime;
      function GetAsLocalDateTime : TDateTime;
      procedure SetAsDateTime(dt : TDateTime);
      procedure SetAsLocalDateTime(dt : TDateTime);

    public
      property AsDateTime : TDateTime read GetAsDateTime write SetAsDateTime;
      property AsLocalDateTime : TDateTime read GetAsLocalDateTime write SetAsLocalDateTime;
  end;

implementation

function JDateHelper.GetAsDateTime : TDateTime;
begin
  Result := Self.getTime / 864e5 + 25569;
end;

procedure JDateHelper.SetAsDateTime(dt : TDateTime);
begin
  Self.setTime((dt - 25569) * 864e5);
end;

function JDateHelper.GetAsLocalDateTime: TDateTime;
begin
  Result := (Self.getTime - 60000 * Self.getTimezoneOffset) / 864e5 + 25569;
end;

procedure JDateHelper.SetAsLocalDateTime(dt: TDateTime);
begin
  Self.setTime((dt - 25569) * 864e5 + 60000 * Self.getTimezoneOffset);
end;

Offline

#10 2016-04-10 19:45:06

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Small change proposal for CrossPlatform

Would you mind commiting a minor change at the "SynCrossPlatformSpecific" and "SynCrossPlatformREST" units.
SmartMS has released a final stable version 2.2.0.4508 and they added an extra "utc" parameter of DateTimeZone type on many DateTime functions, for instance, the function Iso8601ToDateTime requires a implicit parameter to work as expected. I've downloaded the crossplatform units today and made some minor changes, it seems to be working as expected for me.

SynCrossPlatformSpecific.pas
----------------------------
LINE 350 
// function TryEncodeDate(Y,M,D: integer; var Value: TDateTime): boolean;
   function TryEncodeDate(Y,M,D: integer; UTC: DateTimeZone; var Value: TDateTime): boolean;
   
LINE 897 
function TryEncodeDate(Y,M,D: integer; UTC: DateTimeZone; var Value: TDateTime): boolean;
 
LINE 900 
  Value := EncodeDate(Y,M,D,UTC);

LINE 949 
function DateTimeToIso8601(Value: TDateTime): string;  
begin // e.g. YYYY-MM-DD Thh:mm:ss or YYYY-MM-DDThh:mm:ss
  if Value<=0 then
    result := '' else
  if frac(Value)=0 then
    result := FormatDateTime('yyyy-mm-dd',Value,DateTimeZone.UTC) else
  if trunc(Value)=0 then
    result := FormatDateTime('Thh:nn:ss',Value,DateTimeZone.UTC) else
    result := FormatDateTime('yyyy-mm-ddThh:nn:ss',Value,DateTimeZone.UTC);
end;

LINE 977
// TryEncodeDate(Y,M,D,result);
   TryEncodeDate(Y,M,D,DateTimeZone.UTC,result);
   
LINE 990
//result := EncodeDate(Y,M,D)+EncodeTime(HH,MI,SS,0);   
  result := EncodeDate(Y,M,D,DateTimeZone.UTC)+EncodeTime(HH,MI,SS,0);
 


SynCrossPlatformREST.pas
------------------------
LINE 1361
// if (Y=0) or not TryEncodeDate(Y,1+(Value shr (6+6+5+5)) and 15,
       1+(Value shr (6+6+5)) and 31,result) then
	
   if (Y=0) or not TryEncodeDate(Y,1+(Value shr (6+6+5+5)) and 15,
       1+(Value shr (6+6+5)) and 31,DateTimeZone.UTC,result) then	

Offline

Board footer

Powered by FluxBB