You are not logged in.
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
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
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
@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
@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
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
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
The main site is https://www.npmjs.com, but current SyNode implementation not fully compatible with nodejs
Offline
@mpv:
It's OK now, thk you!
Offline