• IDL - how to define and call an objects default method ?

    From R.Wieser@21:1/5 to All on Sat Feb 5 13:41:42 2022
    XPost: microsoft.public.scripting.vbscript

    Hello all,

    I've written a simple array-type object, and would like to be able to set a default getter and setter for the object. IOW, instead of (in VBScript) writing

    MyArray.SetField(3,2) = "42"
    wscript.echo MyArray.GetField(3,2)

    I would be able to use (something like)

    MyArray(3,2) = "42"
    wscript.echo MyArray(3,2)

    Although I've seen the "default action" possibility somewhere (Python IIRC),
    I do not even know if its possible in Windows (win32).

    Question: Is it possible to define (in the typelib?) a default action
    (method, property) for an object ? And if so how ?

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Sun Feb 6 23:46:22 2022
    XPost: microsoft.public.scripting.vbscript

    On Sat, 5 Feb 2022 13:41:42 +0100, R.Wieser wrote:
    Hello all,

    I've written a simple array-type object, and would like to be able to set a default getter and setter for the object. IOW, instead of (in VBScript) writing

    MyArray.SetField(3,2) = "42"
    wscript.echo MyArray.GetField(3,2)

    I would be able to use (something like)

    MyArray(3,2) = "42"
    wscript.echo MyArray(3,2)

    Although I've seen the "default action" possibility somewhere (Python IIRC), I do not even know if its possible in Windows (win32).

    Question: Is it possible to define (in the typelib?) a default action (method, property) for an object ? And if so how ?

    Regards,
    Rudy Wieser

    Property ID 0 will be the default value of an object.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Mon Feb 7 10:25:01 2022
    XPost: microsoft.public.scripting.vbscript

    JJ,

    Property ID 0 will be the default value of an object.

    Thanks. Initially I though you just ment the first-defined one there, and
    it took me a while to realise you might have ment it literally. :-)

    Though it seems that there are a few pitfalls when accessing that default :

    The below won't quite do what I thought it would (only figured that out
    after displaying the "typename" of 'MyArray' :-\ ) :

    MyArray = 42

    I have to use

    MyArray() = 42

    instead.

    And while

    wscript.echo MyArray

    now (calls the defined PropertyGet) returns its value,

    wscript.echo MyArray()

    throws an error. Trying to change the IDLs PropertyGet into a method causes
    a "duplicate definition" error. Not really funny, having to use two
    different notations for the same thing ...

    Any ideas ?

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Tue Feb 8 16:09:21 2022
    XPost: microsoft.public.scripting.vbscript

    On Mon, 7 Feb 2022 10:25:01 +0100, R.Wieser wrote:

    Though it seems that there are a few pitfalls when accessing that default :

    The below won't quite do what I thought it would (only figured that out
    after displaying the "typename" of 'MyArray' :-\ ) :

    MyArray = 42

    I have to use

    MyArray() = 42

    instead.

    And while

    wscript.echo MyArray

    now (calls the defined PropertyGet) returns its value,

    wscript.echo MyArray()

    throws an error. Trying to change the IDLs PropertyGet into a method causes a "duplicate definition" error. Not really funny, having to use two different notations for the same thing ...

    Any ideas ?

    Regards,
    Rudy Wieser

    Start by describing what you actually use for the default property.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Tue Feb 8 14:44:03 2022
    XPost: microsoft.public.scripting.vbscript

    JJ,

    Start by describing what you actually use for the default property.

    Lol, the pot calling the kettle black (no offence ment).

    Would you accept that I use the value 42 for it ? :-)

    If not, what exactly are you asking for ? The IDL definition ? The code
    I wrote ? The way I try to access it from within VBScript ? Something
    else ?

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to R.Wieser on Wed Feb 9 00:11:06 2022
    XPost: microsoft.public.scripting.vbscript

    On Tue, 8 Feb 2022 14:44:03 +0100, R.Wieser wrote:

    Lol, the pot calling the kettle black (no offence ment).

    Would you accept that I use the value 42 for it ? :-)

    If not, what exactly are you asking for ? The IDL definition ? The code I wrote ? The way I try to access it from within VBScript ? Something
    else ?

    Regards,
    Rudy Wieser

    There's simply not enough information to see what went wrong.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Tue Feb 8 20:51:48 2022
    XPost: microsoft.public.scripting.vbscript

    JJ,

    There's simply not enough information to see what went wrong.

    As far as I can tell nothing goes wrong. Its just a question of how to
    handle what I'm getting presented.


    Your suggestion to give a propertyget/propertyset combination an ID of Zero
    did work. Its just that I've than tried to use the VBS commands as
    described in my initial post, but not getting the expected results (I do not see a propertyget / propertyset - and sometimes errors are thrown).

    Though I found out that all objects are supposed to be able to be part of a 'collection', and that the first "( )" is supposed to indicate which element
    of the collection the object is supposed to be.

    IOW, I can now write

    MyArray()(3,4) = 42

    and

    wscript.echo MyArray()(3,4)

    and see my object be accessed - and than throwing an error because it wants
    to access a method, not a property.

    Personally I do not have a problem with that "lets just call a method" behaviour, but I'm now having a bit of a problem in trying to figure out how I'm supposed to discern between a "write" and a "read" action on that
    function ...


    Does that give you a bit more to work with ? If not, please do tell me what you need.

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From R.Wieser@21:1/5 to All on Wed Feb 9 13:11:47 2022
    XPost: microsoft.public.scripting.vbscript

    As far as I can tell nothing goes wrong. Its just a question of how
    to handle what I'm getting presented.

    It looks like I overthought/complicated the (error) results I was getting.
    :-(

    After some more searching and fumbling around it turns out that you can
    define a property with multiple arguments just like you do a regular method.

    [id(0),propget] HRESULT DefProp([in] long Arg1,[in] long Arg2,[out, retval] long* Value); // result=object(x,y) ;(no ".DefProp" needed!)

    [id(0),propput] HRESULT DefProp([in] long Arg1,[in] long Arg2,[in] long
    Value); // object(x,y) = value

    Regards,
    Rudy Wieser

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)