AutoHotkey Community

It is currently May 27th, 2012, 12:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: June 30th, 2011, 4:05 pm 
Offline

Joined: July 14th, 2004, 6:21 am
Posts: 20
I have been attempting to create an associative array that keeps track of window IDs by inserting the ID as the key and a data object as the value. When a window I am tracking is closed I remove it from the array. What I've found is that when using the array.Remove(key), all of the keys with a key ID that is greater than the one being removed (or inserted) are adjusted up/down by one. So now if I have a bunch of tracked windows and close one with an ID in the middle - all of the IDs higher end up getting deleted also since the ID is now corrupted.

Here is an example of what I'm doing:
Code:
Array := {1: 1, 2: 2, 3: 3, 4: 4}

output =
enum := Array._NewEnum()
While enum[key, value]
   output = %output%`nkey(%key%) value(%value%)
MsgBox, %output%

MsgBox, Remove key 2
Array.Remove(2)

output =
enum := Array._NewEnum()
While enum[key, value]
   output = %output%`nkey(%key%) value(%value%)
MsgBox, %output%

; chrome


The basis for this code was taken directly out of the AHK_L description for associative arrays - What am I missing here - Associative arrays shouldn't work this way

_________________
SJKeegs


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2011, 4:44 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Code:
Array.Remove(2, "")

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2011, 4:51 pm 
Offline

Joined: July 14th, 2004, 6:21 am
Posts: 20
Thanks,

I missed segment of the docs.

_________________
SJKeegs


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2012, 8:52 pm 
Offline

Joined: April 23rd, 2009, 6:05 pm
Posts: 34
Thanks for your reply jethrow. I was having the same exact problem and your suggestion fixed it. I should note that all of the documentation I looked at wasn't what you suggested. The CHM help file and online documentation all state the following:

Code:
RemovedValue := Array.Remove(Key)

This should probably be changed to reflect your post, as it was causing the issue. However, if I did miss something, I would appreciate it if someone pointed it out.

Thanks again,
Bob


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 2nd, 2012, 4:59 pm 
Offline

Joined: April 23rd, 2009, 6:05 pm
Posts: 34
For anyone else that may wonder about this. I found it tucked away in the documentation. You can see it here, http://l.autohotkey.net/docs/objects/Object.htm#Remove.

Bob


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2012, 4:29 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
FYI, "Remove()" and "ObjRemove()" in the help file index point there, and in both examples identical to the one you posted, the word "Remove" is a link to that location.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2012, 6:34 am 
Offline

Joined: December 2nd, 2010, 11:14 pm
Posts: 214
Location: Poland
I remember I've had the same problem and I discovered, after reading the Objects documentation page a second time, that there is actually a link at the beginning of the page that (the link) links to a second Object related documentation page:
Image
Uploaded with ImageShack.us
http://l.autohotkey.net/file/users/Memb ... bjects.htm
As I've read the page for the first time, I've thought that the 'Object' link would link to some section on the Objects page, so I haven't clicked it.
And as the AHK_L array is an object, the built-in methods (like .Insert() or .Remove() ) work with the array (bc they (the methods) work with objects).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2012, 7:46 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
As it says in your screenshot, "Object" is a specific type of object whereas the "Objects" page is for objects in general. It might be clearer if you're accustomed to using the Object() function to create objects instead of the newer {} syntax.

Anyway, there is always room for improvement. I'll keep your comments in mind for the next time I am revising the documentation for objects.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, jrav, MSN [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group