Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Fermin
- Posts: 152
- Joined: Fri Jun 05, 2015 10:44 pm
Post
by Fermin » Fri May 14, 2021 2:42 pm
Hi.
I would like to know if an object has a certain property to avoid an error before trying to modify it by code.
For example, is something like this possible?
Code: Select all
if group "cas_b01f14" has the DASHES property then set the dashes of group "cas_b01f14" to empty
In this case would be useful because controls of type 'group' do not have the 'dashes' property
Or else, is there any way to get a list or relation of the 'natural' properties of a given control type?
Thank you very much.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10337
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri May 14, 2021 2:56 pm
Hi.
There is a property called "the properties", that lists all of the, er, properties of any object. Note that the result is in array variable form, so you will want to use the "combine" command to change to an "ordinary" variable.
Once you have that list of properties, you can compare it to other lists, or whatever.
Craig
-
Fermin
- Posts: 152
- Joined: Fri Jun 05, 2015 10:44 pm
Post
by Fermin » Fri May 14, 2021 3:20 pm
Yes, but, for example:
Code: Select all
put the properties of control "cas_b06f10"
Returns nothing.
(In this case "cas_b06f10" is a "graphic" object.)
I am going to check how to use the 'combine' command.
-
Klaus
- Posts: 14206
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri May 14, 2021 3:34 pm
Hola Fermin,
Code: Select all
...
get the properties of control "cas_b06f10"
## graphis HAS the dashes prop:
if IT["dashes"] then
## do your thing
## No dashes:
else
## do some other stuff
end if
...
Best
Klaus
-
SparkOut
- Posts: 2949
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Fri May 14, 2021 3:57 pm
Fermin wrote: ↑Fri May 14, 2021 3:20 pm
Yes, but, for example:
Code: Select all
put the properties of control "cas_b06f10"
Returns nothing.
(In this case "cas_b06f10" is a "graphic" object.)
I am going to check how to use the 'combine' command.
"Returns nothing" is not true - it returns an array, which is why, as Craig said, you need to use "combine" to make it readable with (for example) a simple "put" statement.
Using combine
is not the only way to do anything with the array contents though, as demonstrated by Klaus using direct interrogation of the array key you are interested in.
-
Fermin
- Posts: 152
- Joined: Fri Jun 05, 2015 10:44 pm
Post
by Fermin » Fri May 14, 2021 4:56 pm
Gracias, Klaus for your code, though:
Code: Select all
on mouseUp
answer the dashes of control "cas_b05f17"
-- Replay: 1,9 (correct)
--
--
get the properties of control "cas_b05f17"
## graphis HAS the dashes prop:
if IT["dashes"] then
answer "SI"
else
answer "NO"
end if
-- Replay: "NO"
end mouseup
-
Fermin
- Posts: 152
- Joined: Fri Jun 05, 2015 10:44 pm
Post
by Fermin » Fri May 14, 2021 5:27 pm
Understood and achieved. Thank you all very much for your help:
Code: Select all
on mouseUp
get the properties of control "cas_b05f17"
combine it using return and ":"
answer it
end mouseup

-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10054
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Fri May 14, 2021 5:28 pm
Querying an empty property will always return empty, whether it's empty because the value of the key hasn't been set, or because the key doesn't exist at all.
So if querying for the existence of a key, checking its value may not tell you what you need to know.
You can instead check the list of keys:
Code: Select all
function IsAProperty pObj, pPropName
put the properties of pObj into tA
return pPropName is among the lines of the keys of tA
end IsAProperty/code]
-
PaulDaMacMan
- Posts: 683
- Joined: Wed Apr 24, 2013 4:53 pm
-
Contact:
Post
by PaulDaMacMan » Fri May 14, 2021 9:35 pm
Fermin wrote: ↑Fri May 14, 2021 2:42 pm
I would like to know if an object has a certain property to avoid an error before trying to modify it by code.
Depending on what you're doing, you might also be able to skip the checking entirely by wrapping the property modifying code in
/
control structure, then if the engine doesn't find the property that you're asking to set, instead of throwing an error, it will just move on, or you can
and handle the error in your code.
try
--- try to set your property here ---
[ catch errorVariable
errorStatementsList ]
[ finally
cleanupStatementsList ]
end try