ChangeMapKey()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

ChangeMapKey()

Post by infratec »

Hi,

I have a treegadget generated from a database the fields of the database are stored in a map with the id of the
record as key. This id is also stored as ItemData().

If I 'add' a new member in the tree I generate a new ID with a very large number.

Later if the user decided to save his new tree I update the database or I insert a new record.
But the new record gets an automatic ID by the database.
I have to change the ItemData (no problem) and I have to change the MapKey() (not possible)
So I have to copy the MapElement (CopyMapElemnt() not available) and I have to delete the old one.
It would be much easier if ChangeMapKey() is available.

Btw. I changed now everything to a LinkedList() and store the address of the element as ItemData()
Than I can use ChangeCurrentElement()
That's independent from the ID of the record.

Bernd
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ChangeMapKey()

Post by Demivec »

So instead of this:

Code: Select all

;change key on old record to new value
If FindMapElement(treestuff.d_record(), "123")
  temp.d_record = treestuff()
  DeleteMapElement(treestuff())
  treestuff("987654321") = temp
EndIf
you want to be able to do this?

Code: Select all

;change key on old record to new value
If FindMapElement(treestuff.d_record(), "123")
  ChangeMapKey(treestuff(), "987654321")
EndIf
Post Reply