Objects: Maps==NO???, Arrays==YES

Started by bottomleypotts, October 14, 2022, 04:54:10 AM

Previous topic - Next topic

bottomleypotts

Just confirming this is expected behaviour:

Code (winbatch) Select

m=MapCreate()
o=CreateObject(`WinHttp.WinHttpRequest.5.1`)
m[`object`]=o


Does not work, w[`object`] will not hold the object?

Whereas:

Code (winbatch) Select

a=ArrDimension(3)
o=CreateObject("WinHttp.WinHttpRequest.5.1")
a[0]=o


Will work, and a[0] will hold the object?

td

The map does "hold the object". The problem is that the interpreter does not consider maps to be a valid part of WIL COM object syntax. Consider using the following which works:

Code (winbatch) Select
objHttp = m["object"]
objHttp.SetTimeouts(5000, 5000, 5000, 5000)


We will see if that behavior can be changed in a future release.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Interesting observation: the Consolidated help states: WIL maps are a form of associative array that shares square bracket notation and  variable type with regular WIL arrays


But you seem to be asking if variable types are really upheld? Can't wait to see how the question is addressed.

td

As mentioned above the map does "hold the object". This means that the object "type" is preserved per the example. The problem is strictly with the interpreter parsing of object references. In other words, there is a faulty assumption made in the parser code.

{edit} It should be corrected for the next release.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Using the OP's original script, this illustrates the point.

Code (winbatch) Select
m=MapCreate()
o=CreateObject(`WinHttp.WinHttpRequest.5.1`)
m[`object`]=o

if o ==  m[`object`] then txt = "Object preserved in the map"
else txt = "Object not stored in the map'
Message("Map Object Preservation Test", txt)
exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Just curious...

       
  • A map array can hold CLR objects
  • If multiple objects in map would killing map destroy objects or would they be closed individually, for memory concerns

td

Again WIL maps can hold any object. You just can't use the dot notation with map bracket syntax to access the object method. This applies to both COM and CLR objects. Map elements containing objects are otherwise just like any stand-alone WIL variable containing objects with exactly the same lifetime. In other words, object lifetime is not an issue. The very temporary workaround is to assign the map element to a stand alone variable for method and property access. This workaround applies only to member access. Since there are no lifetime issues you don't need to otherwise worry about it.

This will be fixed in the next release so if you have an active license, the issue will go away in the near to intermediate future.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

bottomleypotts

Quote from: td on October 14, 2022, 09:08:42 AM
Again WIL maps can hold any object. You just can't use the dot notation with map bracket syntax to access the object method. The very temporary workaround is to assign the map element to a stand alone variable for method and property access. This workaround applies only to member access. Since there are no lifetime issues you don't need to otherwise worry about it.

Thank you, this fixed my issue!

td

I just am amazed we didn't have the case in the map unit tests and that no user reported the problem before now. And thanks for taking the time to report the bug.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade