Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #12397 > unrolled thread
| Started by | "R.Wieser" <address@not.available> |
|---|---|
| First post | 2022-02-05 13:41 +0100 |
| Last post | 2022-02-09 13:11 +0100 |
| Articles | 8 — 2 participants |
Back to article view | Back to microsoft.public.scripting.vbscript
IDL - how to define and call an objects default method ? "R.Wieser" <address@not.available> - 2022-02-05 13:41 +0100
Re: IDL - how to define and call an objects default method ? JJ <jj4public@gmail.com> - 2022-02-06 23:46 +0700
Re: IDL - how to define and call an objects default method ? "R.Wieser" <address@not.available> - 2022-02-07 10:25 +0100
Re: IDL - how to define and call an objects default method ? JJ <jj4public@gmail.com> - 2022-02-08 16:09 +0700
Re: IDL - how to define and call an objects default method ? "R.Wieser" <address@not.available> - 2022-02-08 14:44 +0100
Re: IDL - how to define and call an objects default method ? JJ <jj4public@gmail.com> - 2022-02-09 00:11 +0700
Re: IDL - how to define and call an objects default method ? "R.Wieser" <address@not.available> - 2022-02-08 20:51 +0100
Re: IDL - how to define and call an objects default method ? Found it. "R.Wieser" <address@not.available> - 2022-02-09 13:11 +0100
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2022-02-05 13:41 +0100 |
| Subject | IDL - how to define and call an objects default method ? |
| Message-ID | <stlrao$18ah$1@gioia.aioe.org> |
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
[toc] | [next] | [standalone]
| From | JJ <jj4public@gmail.com> |
|---|---|
| Date | 2022-02-06 23:46 +0700 |
| Message-ID | <11xezf8j3kybx$.1b5n7cn4g91t5$.dlg@40tude.net> |
| In reply to | #12397 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2022-02-07 10:25 +0100 |
| Message-ID | <stqonn$vlf$1@gioia.aioe.org> |
| In reply to | #12398 |
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
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@gmail.com> |
|---|---|
| Date | 2022-02-08 16:09 +0700 |
| Message-ID | <6ztcgp3tbz71$.1pd80gla5yth$.dlg@40tude.net> |
| In reply to | #12399 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2022-02-08 14:44 +0100 |
| Message-ID | <stts39$utq$1@gioia.aioe.org> |
| In reply to | #12400 |
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
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@gmail.com> |
|---|---|
| Date | 2022-02-09 00:11 +0700 |
| Message-ID | <xw8d4vgh1hq1.t8tqughxioxy.dlg@40tude.net> |
| In reply to | #12401 |
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.
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2022-02-08 20:51 +0100 |
| Message-ID | <stuhlv$6if$2@gioia.aioe.org> |
| In reply to | #12403 |
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
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2022-02-09 13:11 +0100 |
| Subject | Re: IDL - how to define and call an objects default method ? Found it. |
| Message-ID | <su0b2r$1ur1$2@gioia.aioe.org> |
| In reply to | #12405 |
> 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
[toc] | [prev] | [standalone]
Back to top | Article view | microsoft.public.scripting.vbscript
csiph-web