Page 1 of 1
delete variable arrayname does not work
Posted: Thu Feb 03, 2022 6:29 pm
by mrcoollion
I get an error in the IDE on the following statement of which i am sure it is ok. Used it many times in other places in my stack.
or
Deleting characters with 'delete char ...' works fine.
Working with LC 10.0 (dp1) in Windows 10.
Could this be a bug in the development IDE?
Regards,
Paul
Re: delete variable arrayname does not work
Posted: Thu Feb 03, 2022 7:13 pm
by mrcoollion
Additional to my initial post.
If I declare the array e.g. as a local variable then it works.
Has this been changed lately?
Code: Select all
local aBCD
on mouseup
delete variable aBCD["test"]
end mouseup
regards,
Paul
Re: delete variable arrayname does not work
Posted: Thu Feb 03, 2022 7:22 pm
by SWEdeAndy
I can confirm that in 10.0 (dp1) on Mac it works as expected, no need to declare the variable.
(Although I've never before used "delete variable", only "delete local" and "delete global". But all of them work for me when testing.)
You don't have Strict Compilation Mode on, by any chance?
Re: delete variable arrayname does not work
Posted: Thu Feb 03, 2022 7:38 pm
by dunbarx
When you "delete variable" you only clear the contents of that variable, You do not, er, delete it. Does that matter?
Craig
Re: delete variable arrayname does not work
Posted: Fri Feb 04, 2022 10:33 am
by mrcoollion
SWEdeAndy wrote: ↑Thu Feb 03, 2022 7:22 pm
I can confirm that in 10.0 (dp1) on Mac it works as expected, no need to declare the variable.
(Although I've never before used "delete variable", only "delete local" and "delete global". But all of them work for me when testing.)
You don't have Strict Compilation Mode on, by any chance?
No I checked this before making the post.
@Craig: The purpose is to clean the array of all keys and underlying data.
e.g. 'delete variable aBCD["Test"]' needs to delete all all keys and data below ["Test"].
or 'delete variable aBCD' needs to clear the complete array 'aBCD' of data.
I have been working with the stack I am building with numerous array's and it always works except when I do not declare the array as Global or Local.
Just stumbled upon this issue this week. Also tested this in version Livecode 9.6.5 . Same issue.
Re: delete variable arrayname does not work
Posted: Fri Feb 04, 2022 10:51 am
by SWEdeAndy
Sorry, I see now that this happens on Mac too. When I tested before, I actually put something into the variable first.
The error note seems logical to me though: Variables do not need to be explicitly declared, but you can't delete them until they actually exist. And they don't exist until you refer to them in some way, thereby implicitly declaring them.
So this works:
Code: Select all
on mouseUp
put 1 into aBCD ## No declaring, but here it pops into existence
delete variable aBCD
end mouseUp
But in a real case, you wouldn't start a handler off by deleting a non-existent variable anyway. So, how is this actually causing an error in your code?
Re: delete variable arrayname does not work
Posted: Fri Feb 04, 2022 4:01 pm
by mrcoollion
SWEdeAndy wrote: ↑Fri Feb 04, 2022 10:51 am
Variables do not need to be explicitly declared, but you can't delete them until they actually exist. And they don't exist until you refer to them in some way, thereby implicitly declaring them.
Thanks Andy,
That explains it. I wanted to make sure an array was empty before going into a repeat until routine. However before that routine the array was not used yet.
Thanks for the clarification and example

.
Appreciate it!
Regards,
Paul
Re: delete variable arrayname does not work
Posted: Fri Feb 04, 2022 4:12 pm
by andresdt
I wanted to make sure an array was empty before going into a repeat until routine.
You can do this in other way, for example
Code: Select all
if tVariableArray is an array then put empty into tVariableArray
it was good to learn that you shouldn't call the delete variable without having the variable initialized somehow.
Thanks @Andy