viewpoint-particle

Author Topic: Objects: Maps==NO???, Arrays==YES  (Read 215 times)

bottomleypotts

  • Jr. Member
  • **
  • Posts: 75
Objects: Maps==NO???, Arrays==YES
« on: October 14, 2022, 04:54:10 am »
Just confirming this is expected behaviour:

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

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

Whereas:

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

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

td

  • Tech Support
  • *****
  • Posts: 4208
    • WinBatch
Re: Objects: Maps==NO???, Arrays==YES
« Reply #1 on: October 14, 2022, 06:01:57 am »
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
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

  • Pundit
  • *****
  • Posts: 1706
Re: Objects: Maps==NO???, Arrays==YES
« Reply #2 on: October 14, 2022, 06:05:52 am »
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

  • Tech Support
  • *****
  • Posts: 4208
    • WinBatch
Re: Objects: Maps==NO???, Arrays==YES
« Reply #3 on: October 14, 2022, 06:09:46 am »
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

  • Tech Support
  • *****
  • Posts: 4208
    • WinBatch
Re: Objects: Maps==NO???, Arrays==YES
« Reply #4 on: October 14, 2022, 07:00:00 am »
Using the OP's original script, this illustrates the point.

Code: Winbatch
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

  • Pundit
  • *****
  • Posts: 1706
Re: Objects: Maps==NO???, Arrays==YES
« Reply #5 on: October 14, 2022, 07:17:09 am »
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

  • Tech Support
  • *****
  • Posts: 4208
    • WinBatch
Re: Objects: Maps==NO???, Arrays==YES
« Reply #6 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. 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

  • Jr. Member
  • **
  • Posts: 75
Re: Objects: Maps==NO???, Arrays==YES
« Reply #7 on: October 14, 2022, 09:19:46 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

  • Tech Support
  • *****
  • Posts: 4208
    • WinBatch
Re: Objects: Maps==NO???, Arrays==YES
« Reply #8 on: October 14, 2022, 09:51:11 am »
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