ScriptExtension replacement for ODT - Need some help
Folks using DelphiScript for TestComplete automation have a disadvantage over the other script languages. While JScript and JavaScript and Python allows you to declare classes and instantiate objects, DelphiScript doesn't have that ability.
To this end, in the past, folks have used the ODT object in TestComplete to be able to build classes and objects. However, that object will be deprecated at some point.
To that end, I've started working at a simplistic replacement for the ODT object to be able to allow similar functionality but via a Script Extension. Everything is working pretty well... except for one thing: adding methods to classes. It works fine if the project in which you're calling the object is a JavaScript or JScript project. But once I try using the object in a DelphiScript project, it doesn't work. I don't get any errors, just that the code never actually executes.
Below is the code in the script extension:
var classes = { Declare: function (className) { classes[className] = new function newClass(){ this.AddProperty = addProperty; this.AddMethod = addMethod; }; }, New: function (className) {return new classes[className].constructor()}}; function getclasses(){ return classes; } function addProperty(propertyName, defaultValue) { if (defaultValue === undefined) { this.constructor.prototype[propertyName] = undefined; } else { this.constructor.prototype[propertyName] = defaultValue; } } function addMethod(methodName, stringProc){ function newFunction() { Runner.CallMethod(stringProc) }; this.constructor.prototype[methodName] = newFunction; }
To use this, once the extension is built, here's the way the code would look in a DelphiScript project:
//The unit name is Unit1 procedure test; var myObject1; begin OgreODT.Classes.Declare('test'); OgreODT.Classes.test.AddProperty('prop1'); OgreODT.Classes.test.AddProperty('prop2'); OgreODT.Classes.test.AddMethod('logBlah', 'Unit1.testODT'); myObject1 := OgreODT.Classes.New('test'); myObject1.logBlah(); end; procedure testODT; begin Log.Message('it worked'); end;
Everything executes without error... just that the message never actually gets logged. As mentioned, if I run similar code via JScript or JavaScript, everything works fine.
So... any assistance would be helpful in debugging what's going on here. HKosova.... you've been helpful in the past with these kinds of things.