Page 1 of 1
FindMapElement() need a simple pointer example
Posted: Thu Mar 14, 2024 6:10 pm
by normeus
The example for FindMapElement() should also show the state of the current map element after the command:
Code: Select all
NewMap Country.s()
Country("US") = "United States"
Country("FR") = "France"
Country("GE") = "Germany"
If FindMapElement(Country(), "US")
Debug "'US' is in the country list."
Debug country()
Else
Debug "'US' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "UK")
Debug "'UK' is in the country list."
Debug Country()
Else
Debug "'UK' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "FR")
Debug "'FR' is in the country list."
Debug Country()
Else
Debug "'FR' is NOT in the country list !"
Debug Country()
EndIf
My question is about the pointer it returns when it finds an element. Is it a pointer to a pointer? I've never used it. I was wondering if anyone has an example without using a map of structures just a plain simple map.
Code: Select all
*ptr=FindMapElement(Country(), "US")
If *ptr
ShowMemoryViewer(@*ptr,1000)
EndIf
Thank you.
Norm.
Re: FindMapElement() need a simple pointer example
Posted: Thu Mar 14, 2024 6:49 pm
by idle
it sets the current element to the found element and returns the address of the found element
it returns the pointer and the map is a string so
Code: Select all
*ptr.string =FindMapElement(Country(), "US")
If *ptr
Debug *ptr\s
ShowMemoryViewer(@*ptr\s,1000)
EndIf
Re: FindMapElement() need a simple pointer example
Posted: Thu Mar 14, 2024 11:28 pm
by normeus
Thank you idle!
So this would be an example of the element changing and the usage of the pointer returned by FindMapElement()
Code: Select all
NewMap Country.s()
Country("US") = "United States"
Country("FR") = "France"
Country("GE") = "Germany"
If FindMapElement(Country(), "US")
Debug "'US' is in the country list."
Debug country()
Else
Debug "'US' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "UK")
Debug "'UK' is in the country list."
Debug Country()
Else
Debug "'UK' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "FR")
Debug "'FR' is in the country list."
Debug Country()
Else
Debug "'FR' is NOT in the country list !"
Debug Country()
EndIf
*ptr.string =FindMapElement(Country(), "US")
If *ptr
Debug *ptr\s
Debug Country()
EndIf
I was overthinking the object situation. No more coffee for me.
Thank you.
Norm.
Re: FindMapElement() need a simple pointer example
Posted: Fri Mar 15, 2024 1:16 am
by idle
normeus wrote: Thu Mar 14, 2024 11:28 pm
Thank you idle!
So this would be an example of the element changing and the usage of the pointer returned by FindMapElement()
Code: Select all
NewMap Country.s()
Country("US") = "United States"
Country("FR") = "France"
Country("GE") = "Germany"
If FindMapElement(Country(), "US")
Debug "'US' is in the country list."
Debug country()
Else
Debug "'US' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "UK")
Debug "'UK' is in the country list."
Debug Country()
Else
Debug "'UK' is NOT in the country list !"
Debug Country()
EndIf
If FindMapElement(Country(), "FR")
Debug "'FR' is in the country list."
Debug Country()
Else
Debug "'FR' is NOT in the country list !"
Debug Country()
EndIf
*ptr.string =FindMapElement(Country(), "US")
If *ptr
Debug *ptr\s
Debug Country()
EndIf
I was overthinking the object situation. No more coffee for me.
Thank you.
Norm.
I need coffee today or maybe I skip and straight to the wine!

Re: FindMapElement() need a simple pointer example
Posted: Sat Mar 16, 2024 10:41 am
by morosh
where the type .string is documented?
Re: FindMapElement() need a simple pointer example
Posted: Sat Mar 16, 2024 10:45 am
by infratec
.String is a structure like .Integer .Ascii ...
You can find them in ... 'Tools'->'Structure directory' (or similar, since I use the german IDE)
Re: FindMapElement() need a simple pointer example
Posted: Sat Mar 16, 2024 11:30 am
by morosh
Thank you Infratec