#1 Re: mORMot 1 » uniGui - Server Side JavaScript with SpiderMonkey » 2016-12-26 12:14:23

Thank you very much! You were correct, excellent support...

#2 Re: mORMot 1 » uniGui - Server Side JavaScript with SpiderMonkey » 2016-12-26 11:49:01

Hi, I am using Embarcadero Delphi 10.1 Berlin and uniGui 0.99.96 build 1322.
Your demos run perfectly. New VCL applications using Spidermonkey + required dlls run perfectly.
The problem is when I create a uniGui application then I have this problem. For example I have the following code :


unit ServerModule;

interface

uses
  Classes, SysUtils, uniGUIServer, uniGUIMainModule, uniGUIApplication, uIdCustomHTTPServer,
  uniGUITypes,shellapi,  SynCommons,
  SpiderMonkey,
  SyNode,
  SyNodeProto,
  SyNodeSimpleProto;

type
  TUniServerModule = class(TUniGUIServerModule)
    procedure UniGUIServerModuleCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    FSMManager: TSMEngineManager;
    FEngine: TSMEngine;
    procedure DoOnCreateNewEngine(const aEngine: TSMEngine);
    function DoOnGetEngineName(const aEngine: TSMEngine): RawUTF8;
    procedure doInteruptInOwnThread;
    procedure DoOnJSDebuggerInit(const aEngine: TSMEngine);
    procedure FirstInit; override;
  public
    { Public declarations }
  end;

function UniServerModule: TUniServerModule;

implementation

{$R *.dfm}

uses
  UniGUIVars;

function UniServerModule: TUniServerModule;
begin
  Result:=TUniServerModule(UniGUIServerInstance);
end;

procedure TUniServerModule.doInteruptInOwnThread;
begin

end;

procedure TUniServerModule.DoOnCreateNewEngine(const aEngine: TSMEngine);
begin
  aEngine.doInteruptInOwnThread := doInteruptInOwnThread;
  // in XE actual class of TMemo.lines is TMemoStrings - let's force it to be a TStrings like
  //aEngine.defineClass( TStrings, TStringsProto, aEngine.GlobalObject);
  // define a propery mainForm in the JavaScript
  aEngine.GlobalObject.ptr.DefineProperty(aEngine.cx, Pansichar( self.ClassName) ,
    // proeprty value is a wrapper around the Self
    CreateJSInstanceObjForSimpleRTTI(aEngine.cx, Self, aEngine.GlobalObject),
    // we can enumerate this property, it read-only and can not be deleted
    JSPROP_ENUMERATE or JSPROP_READONLY or JSPROP_PERMANENT
  );

end;

function TUniServerModule.DoOnGetEngineName(const aEngine: TSMEngine): RawUTF8;
begin
  Result:='My JSEngine';
end;

procedure TUniServerModule.DoOnJSDebuggerInit(const aEngine: TSMEngine);
begin

end;

procedure TUniServerModule.FirstInit;
begin
  InitServerModule(Self);
end;

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
var res: jsval;
begin
  FSMManager := TSMEngineManager.Create(StringToUTF8(ExtractFilePath( ParamStr(0) )+'\core_modules'));
  // optionaly increase a max engine memory
  FSMManager.MaxPerEngineMemory := 512 * 1024 * 1024;
  // add a handler called every time new engine is created
  // inside a handler we can add a binding's to a native functions (implemented in Delphi)
  // and evaluate some initial JavaScripts
  FSMManager.OnNewEngine := DoOnCreateNewEngine;
  FSMManager.OnGetName := DoOnGetEngineName;
  //FSMManager.OnDebuggerInit := DoOnJSDebuggerInit;
  // start a JavaScript debugger on the localhost:6000
  //FSMManager.startDebugger('6000');
  // debugger can see engines created after startDebugger() call,
  // so we create a main engine after debugger is started
  // in this example we need only one engine (we are single-thread)
  //Exception is raised here
  FEngine := FSMManager.ThreadSafeEngine(nil);
  FEngine.Evaluate('var i=0;',Self.ClassName+'.js', 1, res)

end;

initialization
  RegisterServerModuleClass(TUniServerModule);
end.

Hope this helps!

#3 mORMot 1 » uniGui - Server Side JavaScript with SpiderMonkey » 2016-12-25 20:14:13

chronisvel
Replies: 4

Hi, I tried implementing server side javascript with uniGui, using SpiderMonkey, SyNode. I always get an error :
Project XXXXX.exe raised exception class $C0000005 with message 'c00000005 ACCESS_VIOLATION'

When running the same lines of code in a VCL application everynting works fine.

The exception Is raised in Spidermonkey Unit in the line :
function JS_NewRuntime(maxbytes: uint32; maxNurseryBytes: uint32; parentRuntime: PJSRuntime): PJSRuntime;
  cdecl; external SpiderMonkeyLib;

What should I do? Is mormot's implementation incompatible with uniGui? If so what are my alternatives?

Thanks...

#4 Re: mORMot 1 » Changes of html views is not reflected in an up and running MVC server » 2016-02-16 14:55:31

Please, can you answer my question?
Could you please explain what is the proper way to do it, how can I disable cache of the templates?

#6 mORMot 1 » Connection to oracle » 2016-02-05 14:36:00

chronisvel
Replies: 2

Based on the MVC demo, connection to SQLITE3 is achieved by this (simplified by me) code:
  aModel := CreateModel;
  aServer := TSQLRestServerDB.create(aModel,ChangeFileExt(ExeVersion.ProgramFileName,'.db'));
  aServer.DB.Synchronous := smNormal;
  aServer.DB.LockingMode := lmExclusive;
  aServer.CreateMissingTables;
  aApplication := TMyMVCApplication.Create;
  aApplication.Start(aServer);
...

How can I connect to an ORACLE server instead?

#7 Re: mORMot 1 » Changes of html views is not reflected in an up and running MVC server » 2016-01-25 20:23:30

Could you please explain what is the proper way to do it? How can I disable cache of the templates?
For example:
TMVCRunOnRestServer.Create(Self).SetCache('Default',cacheNone,1);
does not work, cache is not disabled.

#8 mORMot 1 » Changes of html views is not reflected in an up and running MVC server » 2016-01-01 13:13:24

chronisvel
Replies: 5

I just created my first MVC server. When I change the html of a view, the changes are not visible in the browser. If I terminate the server and restart the application, changes are visible. I want to be able to change view files without restating the server, what should I do?

Board footer

Powered by FluxBB