Forum Discussion

tristaanogre's avatar
tristaanogre
Esteemed Contributor
7 years ago

OgreODT Script Extension

OK... version 1.0 of the ScriptExtension to replace some of the functionality of deprecated ODT is available for download.  You can grab it at 

 

https://bitbucket.org/privateteamogre/scriptextensions/downloads/OgreODT.tcx

 

The initial release of this runtime object is to add ODT.Classes support for use in DelphiScript projects.  This will allow a user to Declare and create new instances of objects for use in DelphiScript code.

 

A sample code for this is below:

procedure test;
var myObject1;
var argumentArray : array[0..1];
begin
    OgreODT.Classes.Declare('test');
    OgreODT.Classes.test.AddProperty('prop1');
    OgreODT.Classes.test.AddProperty('prop2');
    OgreODT.Classes.test.AddMethod('runTest', 'Unit2.testODT');
    myObject1 := OgreODT.Classes.New('test');
    argumentArray[0] := 'test';
    argumentArray[1] := 'another test';
    aqObject.CallMethod(myObject1, 'runTest', argumentArray);
end;

This code declares a class "test" and adds two properties to it and a method.  The method calls the code at 'Unit2.testODT'.

 

There are some differences in how this works from the original ODT objects:

 

1) In DelphiScript projects, in order to call the methods of the object, you need to use aqObject.CallMethod.  I haven't figured out yet how to get this to work more natively. For other languages, calling the object method directly works just fine

2) If you need to pass parameters to your method, they need to be passed as an array and then utilized within your method as elements of that array.  This is because I haven't been able to find an easy way (yet) to make the number of parameters in the object method variable for DelphiScript utilization. 

 

The above to caveats I'll be continuing to work on in future versions.  Feel free to ask for assistance in implementation.  As always, if you use this, all I ask is attribution and that any derivatives of this contain that attribution as well.

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Robert,

     

    Great work, thank you for sharing it!

     

    I didn't look into the code, so asking here: given that 'test' name in your code sample is dynamic parameter, is it possible instead of

        OgreODT.Classes.Declare('test');
        OgreODT.Classes.test.AddProperty('prop1');

    write this:

     

        OgreODT.Classes.Declare('test');
        OgreODT.Classes['test'].AddProperty('prop1');

    ?

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      In DelphiScript, no, that doesn't work.  You can use that notation in JScript and JavaScript however.