Object.Delete(Key) doesn't work in my case. Looks like a bug.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Object.Delete(Key) doesn't work in my case. Looks like a bug.

23 Mar 2024, 08:38

My test code:
test.zip
(25.12 KiB) Downloaded 6 times
(I'm using geek's CJson 0.4.1 for AHK 1)

I have tried it in V2 with the same dada and geek's CJson for V2. Works fine.

Code: Select all

fileRead, data, data.txt
MyWords:=JSon.load(data)
NewWord :="AAA"

MyWords[NewWord] := "2"  ;works
msgbox, % MyWords[NewWord]

MyWords.Delete(NewWord) ;does not work
msgbox, % MyWords[NewWord]

;
; cJson.ahk 0.4.1
User avatar
mikeyww
Posts: 26986
Joined: 09 Sep 2014, 18:38

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

23 Mar 2024, 09:08

Hello,

This is not necessarily a bug-- I am not certain-- but something unexpected. If Delete is a key in your array, then word.Delete(NewWord) refers to your array property or element rather than referring to the Delete method.

Code: Select all

#Requires AutoHotkey v1
NewWord := "AAA"
word := {"AAA": 1, "Delete": "NOT A METHOD"}
MsgBox % word[NewWord]
word.Delete(NewWord)
MsgBox % word.Delete
MsgBox % word[NewWord]
For all types of objects, the notation Object.LiteralKey can be used to access a property, array element or method, where LiteralKey is an identifier or integer and Object is any expression. Identifiers are unquoted strings which may consist of alphanumeric characters, underscore and, in [v1.1.09+], non-ASCII characters.
Source: Objects - Definition & Usage | AutoHotkey v1
Perhaps AHK should use the presence of parentheses to know that the statement uses a method.

I think that this is a bug; it appears that when the array contains a key called "Delete", the Delete method can no longer be used.
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

23 Mar 2024, 12:51

I think that this is a bug; it appears that when the array contains a key called "Delete", the Delete method can no longer be used.
Thank you mikeyww! You are the best! I know lexikos posted "End of life v1.1" yesterday, but I really hope he can get this fixed. Cause I'm still a V1.1 guy :( :( :(. I hope someone can bring this to his attention. :( :( :(.
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

24 Mar 2024, 06:20

You might have seen the response from Lexikos on the bug report board. I understand his point, but how can I remove key-value from the array? It's not practical to rebuild the array every time I need to remove a key-value pair.

Code: Select all

#Requires AutoHotkey v1

words := {"AAA": 1, "Delete": 2, "Add": 3, "Hello": 4, "Remove": 4}
NewWord := "AAA"

words[NewWord] := "5" ; Works
MsgBox % words[NewWord]

words.Delete(NewWord) ; Doesn't work
MsgBox % words[NewWord]
User avatar
mikeyww
Posts: 26986
Joined: 09 Sep 2014, 18:38

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

24 Mar 2024, 07:34

You can do it in v2.

Code: Select all

#Requires AutoHotkey v2.0
word := Map()
For pair in StrSplit(FileRead('data.txt'), ',', '{}')
 part := StrSplit(pair, ':', '" '), word[part[1]] := part[2]
NewWord := 'AAA'
MsgBox word[NewWord]
word.Delete(NewWord)
MsgBox word.Has(NewWord)
MsgBox word["Delete"]
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

24 Mar 2024, 12:04

Thank you mikeyww! I add ‘K_’ to all the keys as a workaround, and it is working properly now.
User avatar
mikeyww
Posts: 26986
Joined: 09 Sep 2014, 18:38

Re: Object.Delete(Key) doesn't work in my case. Looks like a bug.

24 Mar 2024, 12:10

Sounds good. Actually, any prefix, suffix, etc. that prevents having the conflicting key will work.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Bing [Bot], captainsmackyou, mikeyww and 68 guests