Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

9 views
Skip to first unread message

R.Wieser

unread,
Feb 5, 2022, 7:42:05 AM2/5/22
to
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

unread,
Feb 6, 2022, 11:46:25 AM2/6/22
to
Property ID 0 will be the default value of an object.

R.Wieser

unread,
Feb 7, 2022, 4:28:27 AM2/7/22
to
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

unread,
Feb 8, 2022, 4:09:25 AM2/8/22
to
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.

R.Wieser

unread,
Feb 8, 2022, 8:44:13 AM2/8/22
to
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

unread,
Feb 8, 2022, 12:11:09 PM2/8/22
to
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.

R.Wieser

unread,
Feb 8, 2022, 2:52:34 PM2/8/22
to
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

unread,
Feb 9, 2022, 7:12:14 AM2/9/22
to

> 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


0 new messages