Discussion:
IDL - how to define and call an objects default method ?
(too old to reply)
R.Wieser
2022-02-05 12:41:42 UTC
Permalink
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
JJ
2022-02-06 16:46:22 UTC
Permalink
Post by R.Wieser
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.
R.Wieser
2022-02-07 09:25:01 UTC
Permalink
JJ,
Post by 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
JJ
2022-02-08 09:09:21 UTC
Permalink
Post by R.Wieser
The below won't quite do what I thought it would (only figured that out
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.
R.Wieser
2022-02-08 13:44:03 UTC
Permalink
JJ,
Post by 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
JJ
2022-02-08 17:11:06 UTC
Permalink
Post by R.Wieser
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.
R.Wieser
2022-02-08 19:51:48 UTC
Permalink
JJ,
Post by 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
R.Wieser
2022-02-09 12:11:47 UTC
Permalink
Post by R.Wieser
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

Loading...