#1 2017-11-24 04:20:43

fadhilah
Member
Registered: 2017-07-19
Posts: 5

Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Dear all,

First time trying mormot and try to connect to TSQLHttpServer remotely with code

Var
  I: Integer;
  fClientRest:TSQLRestClientHTTP;
  fClientModel: TSQLModel;
  fKaryawan: TSQLKaryawan;
begin
  fClientModel:=TSQLModel.Create([TSQLKaryawan,TSQLKeluarga],'root');
  fClientRest:=TSQLRestClientHttp.Create('localhost',8080,fClientModel);
  try
    if fClientRest.Connect then begin
       Showmessage('Connect');
      fKaryawan:= TSQLKaryawan.CreateAndFillPrepare(fClientRest,'','');
       Showmessage('fKaryawan Filled');
    end
    else
      Button1.Enabled := false;
  except
    on E: Exception do raise
  end;
end;

but got error : [dcc32 Error] Unit3.pas(49): E2010 Incompatible types: 'TSQLRecordClass' and 'class of TSQLKaryawan'
at line   fClientModel:=TSQLModel.Create([TSQLKaryawan,TSQLKeluarga],'root');

but when TSQLModel change to
fClientModel:=TSQLModel.Create([TSQLRecordClass(TSQLKaryawan),TSQLRecordClass(TSQLKeluarga)],'root');
and error changes to
[dcc32 Error] Unit3.pas(56): E2250 There is no overloaded version of 'CreateAndFillPrepare' that can be called with these arguments
at line   fKaryawan:= TSQLKaryawan.CreateAndFillPrepare(fClientRest,'','');

and then I change TSQLKaryawan.CreateAndFillPrepare to
fKaryawan:= TSQLKaryawan(TSQLRecordClass.CreateAndFillPrepare(fClientRest,'','',[]));
but compilled but when running show error
"Project TestRestClient_httpServer.exe raised exception class ERestException with message 'TSQLRecord should be part of the Model'."

Did anybody can help to solve whats wrong with my code?

Offline

#2 2017-11-24 07:32:33

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Have you called CreateMissingTables()?

Offline

#3 2017-11-24 08:31:11

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

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

The compiler error is pretty clear: TSQLKaryawan should inherit from TSQLRecord.

Forcing the type by using TSQLRecordClass(TSQLKaryawan) is just plain wrong.

Offline

#4 2017-11-24 08:52:47

fadhilah
Member
Registered: 2017-07-19
Posts: 5

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Dear ab, thanks for fast reply.

Did you have suggestion to resolve? Iam using XE10.2 Lite

Offline

#5 2017-11-24 08:56:03

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

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

TSQLKaryawan should inherit from TSQLRecord.

What do you not understand in this?

Offline

#6 2017-11-24 09:05:30

fadhilah
Member
Registered: 2017-07-19
Posts: 5

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Yes ab,  I know that TSQLKaryawan should inherit from TSQLRecord
my class code like

TSQLKaryawan = class(TSQLRecord)
  protected
    fCenter: RawUTF8;
 ...

but i dont understand is why I got error [dcc32 Error] Unit3.pas(49): E2010 Incompatible types: 'TSQLRecordClass' and 'class of TSQLKaryawan'
when coding fClientModel:=TSQLModel.Create([TSQLKaryawan,TSQLKeluarga],'root');
You suggest it's compiler error?

Offline

#7 2017-11-24 09:30:21

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

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Please do not put a lot of code in the forum, as stated by the forum rules.
https://synopse.info/forum/misc.php?action=rules

I don't understand the problem of your code.
Aren't you mixing regular (SynCommons/mORMot.pas) and cross-platform units?

Offline

#8 2017-11-24 09:39:01

fadhilah
Member
Registered: 2017-07-19
Posts: 5

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Oh, sorry about that,
First time i using SynCommons/mORMot and CrossPlatform, but after error i delete SynCommons/mORMot and only using CrossPlatform, but error still exists, confuse where i miss

Last edited by fadhilah (2017-11-24 09:41:21)

Offline

#9 2017-11-24 10:11:12

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

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

Don't mix the units.

Either you use SynCommons/mORMot, or you use CrossPlatform units.
There is a TSQLRecord type definition in both, which are incompatible.

Get rid of all the CrossPlatform units reference in your "uses" clause.
Only use SynCommons/mORMot.

Offline

#10 2017-11-24 12:54:46

fadhilah
Member
Registered: 2017-07-19
Posts: 5

Re: Error TSQLRestClientHTTP to connect to Remote Rest Server via HTTP

I already remove SynCrossPlatformRest, but  found error [dcc32 Error] Unit3.pas(30): E2003 Undeclared identifier: 'TSQLRestClientHTTP'.

Thats why i remove SynCommons and mORMot and used SynCrossPlatformRest again. I got mORMot from github

Offline

Board footer

Powered by FluxBB