Hi,
is there an easy way to rename a map element? A structured map, of course. Right now I copy all values one by one into the new element.
Easy way to rename a map element?
Easy way to rename a map element?
Good morning, that's a nice tnetennba!
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500
Re: Easy way to rename a map element?
You mean rename the key?
Not to my knowledge.
But you can easily do
MyMap(NewKey) = MyMap(OldKey)
to copy the whole structure.
Not to my knowledge.
But you can easily do
MyMap(NewKey) = MyMap(OldKey)
to copy the whole structure.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Easy way to rename a map element?
Yes, the key.
...does this not just copy the pointer to the map element? What about maps and lists within the map element?
...does this not just copy the pointer to the map element? What about maps and lists within the map element?
Good morning, that's a nice tnetennba!
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500
Re: Easy way to rename a map element?
No, it is the short form for CopyStructure(@MyMap(OldKey), @MyMap(NewKey), MapStructure).jacdelad wrote: Sun Mar 01, 2026 8:45 pm Yes, the key.
...does this not just copy the pointer to the map element? What about maps and lists within the map element?
It is a full copy of all structure fields, string, lists etc.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Easy way to rename a map element?
Better to use a map with integer to heap allocated structures then use
findmapelement deletemapelemnt and addmapelement
You can hack the mapkey name and get it in a foreach but it will break the functionality of the map so you can only do it safely when the map is static and only once.
findmapelement deletemapelemnt and addmapelement
Code: Select all
Procedure RenameMapElement(Map mp(),oldkey.s,newkey.s)
Protected *ele.integer,value
*ele = FindMapElement(mp(),oldkey)
If *ele
value = *ele\i
DeleteMapElement(mp(),oldkey)
AddMapElement(mp(),newkey)
mp() = value
ProcedureReturn mp()
EndIf
EndProcedure
Global NewMap foo.i()
foo("abc") = 123
foo("bcd") = 234
RenameMapElement(foo(),"abc","cba")
Debug foo()
;hack it but only if it's static
Structure mapelement
*next
key.s
EndStructure
*ele.mapelement = FindMapElement(foo(),"cba") - SizeOf(mapelement)
PokeS(@*ele\key,"abc")
ForEach foo()
Debug MapKey(foo()) + " " + Str(foo())
Next
Re: Easy way to rename a map element?
Thanks very much!
Good morning, that's a nice tnetennba!
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500
PureBasic 6.30/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
Raspi 400/500

