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.
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.
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.
As far as I can tell nothing goes wrong. Its just a question of how
to handle what I'm getting presented.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:28:39 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,851 |