#1 2018-12-10 14:23:14

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 409

Variable sharing between Delphi and Javascript

I have see the sample 22 about use of javscript with Mormot and this is clear enough.
However on my case I'd like to do the:
1. set from Delphi some Javascript variables value (float and integer);
2. run Javscript code;
3. get Javascrit variables value to use they on Delphi code.

On documentation I don't see nothing about variables transition.

What is the best approach for my goal?

regards

Offline

#2 2018-12-10 16:12:39

edwinsn
Member
Registered: 2010-07-02
Posts: 1,049

Re: Variable sharing between Delphi and Javascript

IIRC, although it's unclear about that, but actually sample 22 is outdated - it uses SpiderMonkey24 and it's deprecated by @MPV and their team.

The latest is the wrapper for SpiderMonkey52, you should look at <mORMot_root>\SyNode\Samples


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2018-12-10 16:42:30

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 409

Re: Variable sharing between Delphi and Javascript

edwinsn wrote:

The latest is the wrapper for SpiderMonkey52, you should look at <mORMot_root>\SyNode\Samples

There is a lot of confusion in this folder.
The examples are not very clear.

Offline

#4 2018-12-10 16:52:58

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,076
Website

Re: Variable sharing between Delphi and Javascript

There is no "variables" in JavaScript.  What you see as a variable is either a property of a global object (in case you wrote var myVar not inside the function) or a property of a hidden "scope variable object" (in case of var inside function or let inside block).

So to pass a "variable" into JS either pass it as a parameter to function or set as property of global object (or some member of global object). To get variable value back get a value of global object property with the same name as your variable (or create a function in JS what return your value)

Last edited by mpv (2018-12-10 16:53:30)

Offline

#5 2018-12-10 17:00:16

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 409

Re: Variable sharing between Delphi and Javascript

mpv wrote:

So to pass a "variable" into JS either pass it as a parameter to function or set as property of global object (or some member of global object). To get variable value back get a value of global object property with the same name as your variable (or create a function in JS what return your value)

I think I understand.
Please do some cleaning on <mORMot_root>\SyNode\Samples folder when you have time smile

Offline

#6 2018-12-12 17:57:54

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,076
Website

Re: Variable sharing between Delphi and Javascript

array81 wrote:

Please do some cleaning on <mORMot_root>\SyNode\Samples folder when you have time smile

You are right. This will be a good task for me on Christmas smile

Offline

#7 2018-12-12 18:25:39

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 409

Re: Variable sharing between Delphi and Javascript

mpv wrote:

You are right. This will be a good task for me on Christmas smile

If possible can you convert the sample 22 (based old spidermonkey implementation) because I have some problem to convert it to use it with the new implementation. Thanks.

Offline

Board footer

Powered by FluxBB