#1 2017-09-12 02:04:52

mrluis
Member
From: Florida
Registered: 2017-08-20
Posts: 24

Newbee question... SyNode

I'm looking to introduce the capability to execute javascript into my project. The idea is to allow customers to respond to a web broker server with java script code. However, I'm not looking to support all node related stuff... I would like to keep it simple... plain javascript... trigger a single event, and allow the user to access to a limited number of Delphi classes/functions... 

Sample...

- When web broker load, I load from a database a number of javascript "files" and prep the engine...
- on '/plugin' action event of web broker, I'll like to call a function from Delphi to Javascript...
- Inside the Javascript, I'll like the customer to be able to access data by using a Delphi function... something like GetRecord(tableName, recordID)

sample Delphi functions

procedure RegisterWebEvent(pathName:String,functionName:String);  // this allow the javascript to self register what event will be responding to
begin
  // add information to a tdictionary, or array, or linked list, or anything!
end;

function getRecord(tableName:String;recordID:String):String;
begin
  myDataset.sql.text := 'Select * from ' + tableName + ' where id = ' + QuotedStr(recordID);
  myDataset.Open;
  if not myDataset.EOF then begin
    /*
      somehow wrap the return into something like...
         {
          "id":"123",
          "name":"Peter",
          "age":"54"
         }
      I know I can loop thru the fieldsDef to create this, but not sure if I should return a string...
    */
    end; 
end;

sample javascript script

  function MyResponse(request, response){
     response.content = '<html><body>hello there </body></html>';
  }
  // call delphi to register
  RegisterWebEvent('sayHello','MyResponse');


  function getSomeData(request, response){
   // access the request object to get a passed parameter
   var id = request.contentQuery.values['id'];
   // get data by using a delphi code
    var myRec = getRecord('Customers','423423');
    if (myRec){
      response.content = myRec.Name;
      }   
   }
 // call delphi to register
  RegisterWebEvent('getData','getSomeData');

At this stage, when I receive a '/pluggin' event, I'll check the next path level and see if there is any registered event...

If I receive /pluggin/getData?id=34 I'll call the javascript function getSomeData


That's it... no Node, no debugging, no external modules, no dll, no nothing... just pure javascript...

Questions...
  - Can I use SyNode and isolate out the "node" part of it, but still use SpiderMonkey 45 or 52?
  - Can I create Delphi function to be called from javascript?
     - if yes, can I return a javascript object (based on a record?), meaning the object is not yet defined and will depend on data returned by a dataset
  - Can I call javascript functions from Delphi....
  - Can I pass Delphi classes to javascript (like TRequest/TResponse)?

tks,
Luis

Offline

#2 2017-09-19 17:32:44

mrluis
Member
From: Florida
Registered: 2017-08-20
Posts: 24

Re: Newbee question... SyNode

I'm assuming the answers are...
  - Can I use SyNode and isolate out the "node" part of it, but still use SpiderMonkey 45 or 52?
   No... There are plenty of code that seems to be hardcoded attached to external js files (like EvaluateModule('synode.js') or aEng.EvaluateModule('DevTools\Debugger.js'))
  - Can I create Delphi function to be called from javascript?
     - if yes, can I return a javascript object (based on a record?), meaning the object is not yet defined and will depend on data returned by a dataset
      Yes, at least the first part... the second part, I'm not sure, but I can surely return a string and call eval to convert to Javascript Object...
  - Can I call javascript functions from Delphi....
   Yes
  - Can I pass Delphi classes to javascript (like TRequest/TResponse)?
   Maybe... you can use delphi class on javascript, not sure if I can pass them as parameters...


Can someone confirm this is correct? or Am I missing something?

Offline

#3 2017-09-22 05:08:03

mrluis
Member
From: Florida
Registered: 2017-08-20
Posts: 24

Re: Newbee question... SyNode

FluxBB bbcode test

Offline

Board footer

Powered by FluxBB