#1 2017-01-30 14:48:53

markzql
Member
Registered: 2017-01-30
Posts: 12

In SyNode can't register a Class with the methods more than 255.

Hi,

In SyNode defineClass can't register a Class with more than 255 methods?
  How can I register a Class with more than 255 methods?

The Code In SyNode.pas

/// Define a Delphi class as JS class (prototype), so it can be created via new:
    //    engine.defineClass(TmyObject, TSMNewRTTIProtoObject);
    //  and in JS
    //    var myObj = new TmyObject();
    // - Class will be exposed in the aParent javaScript object, if aParent is omitted - in the global object
    // - AProto parameter can be a TSMCustomProtoObject descendant (TSMSimpleRTTIProtoObject, TSMNewRTTIProtoObject)
    // WARNING - possible prototypes count is limited to 255 - JSCLASS_GLOBAL_SLOT_COUNT = 76 for SM45,
    //   so it is better to use a bindings, add where a native functions and wrap it in class into the JavaScript
    //   see `fs.js` for sample.
    function defineClass(AForClass: TClass; AProto: TSMCustomProtoObjectClass; aParent: PJSRootedObject = nil): TSMCustomProtoObject;

Offline

#2 2017-01-30 14:54:11

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

Re: In SyNode can't register a Class with the methods more than 255.

Please don't create directly such a ticket.

Wait for the discussion in the forum first.

My guess is that it is a limitation if you register a class in the global scope only, which is not a good idea.

Offline

#3 2017-01-30 14:58:53

markzql
Member
Registered: 2017-01-30
Posts: 12

Re: In SyNode can't register a Class with the methods more than 255.

Ok,
  I want Register a COM DLL in JS, and I have import it, it have more than 300 methods,
Is there some idea I can Call the Mothods like:
var a = new TMyClass(); a.abc();

Thanks!

Offline

#4 2017-01-31 16:01:55

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

Re: In SyNode can't register a Class with the methods more than 255.

@markzql: As AB note, the code you provide is about a total number of Delphi classes we can wrap for a JS engine - it is limited to 76
But limitation about method count also exist (255 per class) - this is because we use a JSObject "Slots" to store a information about reference to Delphi methods, and slot count is limited by 255 in current SpiderMonkey implementation.

For your task (COM dll) we have a "COM bridge" between JS and any COM DLL (so, you do not need to create a additional wrappers between COM and Delphi)
I publish a package with source codes to our packages registry. Use a command

npm i @unitybase/com-bridge --registry http://registry.unitybase.info

to download it (you need UBComBridge.dpr & uUBComBridge.pas  in case you do not want to require a package using require)

Offline

#5 2017-02-01 10:11:10

markzql
Member
Registered: 2017-01-30
Posts: 12

Re: In SyNode can't register a Class with the methods more than 255.

@mpv:
Very thanks!
But I have a problem with the var out parameters, like:

function GetClientSize(hwnd: Integer; out width: OleVariant; out height: OleVariant): Integer;

I can't get the width and height with this function, can I get the param name from the js?
JS Code:

var width = 0;
var height = 0;
var ret = com.GetClientSize(hwnd,width,height); 
//width and height  always 0 

Offline

#6 2017-02-01 11:31:39

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

Re: In SyNode can't register a Class with the methods more than 255.

There is no "output" parameters in JS.
The workaround is to modify a COM object and add a 2 function getClientWidth(hwnd) & getClientHeight(hwnd)
Another way is to modify a COM_CallFunction and return a output parameters as a properties of result JSObject, to get something like this:

var ret = com.GetClientSize(hwnd); 
console.log(ret); // {result: 0, width: 12, height: 22}
// or in case parameters is not "named"
console.log(ret); // {0: 0, 1: 12, 2: 22}

Contribution is welcome!

Offline

#7 2017-02-01 12:24:10

markzql
Member
Registered: 2017-01-30
Posts: 12

Re: In SyNode can't register a Class with the methods more than 255.

Ok, Thank you!
I can't modify the COM, it is theothers,
So I must modify the CallFunction.
Thank you again!

The other question, where can I download more nodejs lib?

Offline

#8 2017-02-01 15:02:01

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

Re: In SyNode can't register a Class with the methods more than 255.

The main site is https://www.npmjs.com, but current SyNode implementation not fully compatible with nodejs

Offline

#9 2017-02-02 05:01:38

markzql
Member
Registered: 2017-01-30
Posts: 12

Re: In SyNode can't register a Class with the methods more than 255.

@mpv:
It's OK now,  thk you!

Offline

Board footer

Powered by FluxBB