You are not logged in.
Pages: 1
Hi all;
I develop mormot server based on document and demos but I can't insert data to table with interface system;
thanks;
// interfaces.pas
unit Interfaces;
interface
uses SynCommons;
type
INote = interface(IInvokable)
['{4C284438-8107-4237-9932-F844472A0369}']
function addNote(Title,Body:RawUtf8):Boolean;
end;
implementation
uses mORMot;
initialization
TInterfaceFactory.RegisterInterfaces([TypeInfo(INote)]);
end.
// models.pas
unit Models;
interface
uses mOrmot,SynCommons;
type
TSQLNote=class(TSQLRecord)
private
fTitle,fBody:RawUTF8;
public
function check:Boolean;
published
property Title:RawUTF8 read fTitle write fTitle;
property Body:RawUTF8 read fBody write fBody;
end;
function CreateModel:TSQLModel;
implementation
function CreateModel:TSQLModel;
begin
Result:=TSQLModel.Create([TSQLNote]);
end;
{ TSQLNote }
function TSQLNote.check: Boolean;
begin
Result:=True;
end;
end.
// main.pas
unit Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,mORMot,mORMotHttpServer,MormotSQLite3,SynCommons,Interfaces,SynSQLite3Static;
type
TServiceNote=class(TInterfacedObject,INote)
public
function addNote(Title: RawUTF8; Body: RawUTF8): Boolean;
end;
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
aModel: TSQLModel;
aServer: TSQLRestServer;
aHTTPServer: TSQLHttpServer;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
uses Models;
procedure TForm2.FormCreate(Sender: TObject);
begin
aModel:=CreateModel;
aServer:=TSQLRESTServerDB.Create(aModel,'Database.db');
aServer.ServiceDefine(TServiceNote,[INote],sicShared);
aHTTPServer:=TSQLHttpServer.Create('8096',aServer,'+',useHttpApiRegisteringURI);
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
aModel.Free; aServer.Free; aHTTPServer.Free;
end;
{ TServiceDemo }
function TServiceNote.addNote(Title, Body: RawUTF8): Boolean;
begin
end;
end.
Last edited by mohsenti (2015-04-11 08:18:52)
Offline
I don't know continuation and how to work with DB in interface based system.
Offline
Do you mean something like:
myNode := TSQLNote.Create;
myNode.Title := 'no title';
aServer.Add(myNote);
?
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Do you mean something like:
myNode := TSQLNote.Create; myNode.Title := 'no title'; aServer.Add(myNote);
?
Yes but can't access aServer in TServiceNote
function TServiceNote.addNote(Title, Body: RawUTF8): Boolean;
begin
// can't access aServer here
end;
Offline
If your IServiceNote is supposed to be accessible in the clients, you can add a field of type TSQLRESTServerDB to TServicenote, and assign its value in the constructor, then in your AddNote() method you'll be able to access your REST DB SERVER.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Use ServiceContext: TServiceRunningContext threadvar or the CurrentServiceContext function (from a package).
Offline
Oops! Sorry for provided the non-standard method, that what came from my mind when I read your question
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Use ServiceContext: TServiceRunningContext threadvar or the CurrentServiceContext function (from a package).
Hi Arnaud,
I'm using the latest rev. committed today, when being accessed on the server side, ServiceContext.Request is always nil. Any comments? Thanks.
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Pages: 1