I'm use PureBasic 5.62 (Linux - x64).
Please see my question in the code comments.
Code: Select all
Structure Country_
name.s
continent.s
EndStructure
NewMap Country.Country_()
; Regular way to add an element
With Country("US")
\name = "United States"
\continent = "America"
EndWith
Debug "Map Element US = " + @Country()
; The same using AddMapElement()
Define *france.Country_ = AddMapElement(Country(), "FR")
With *france
\name = "France"
\continent = "Europe"
EndWith
Debug "Map Element *france = " + *france
; Not documented way, but similar the regular way.
; This key don't exists then new map element is created and pointer returned as expected! Exactly as AddMapElement...
Define *brazil.Country_ = Country("BR")
*brazil\name = "Brazil"
*brazil\continent = "America"
Debug "Map Element *brazil = " + *brazil
; But new map element isn't accessible
ForEach Country()
Debug Country()\name + " - " + Country()\continent + " | Pointer = " + @Country()
Next
Debug "FindMapElement BR = " + FindMapElement(Country(), "BR")
Debug "MapSize = " + MapSize(Country())
I think accessing the map with a new key should implicitly invoke AddMapElement or return #Null as it does in FindMapElement.Remarks
This function is not mandatory when dealing with maps, the elements are automatically added when affecting them.
What do you think?
Att,
Danilo S. Coelho.