Page 1 of 1

To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 2:42 pm
by Fermin
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.

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 2:56 pm
by dunbarx
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

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 3:20 pm
by Fermin
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.

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 3:34 pm
by Klaus
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

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 3:57 pm
by SparkOut
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.

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 4:56 pm
by Fermin
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

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 5:27 pm
by Fermin
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
:)

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 5:28 pm
by FourthWorld
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]

Re: To know the specific properties of a certain type of control.

Posted: Fri May 14, 2021 9:35 pm
by PaulDaMacMan
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

Code: Select all

try
/

Code: Select all

end try
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

Code: Select all

catch
and handle the error in your code.

try
--- try to set your property here ---
[ catch errorVariable
errorStatementsList ]
[ finally
cleanupStatementsList ]
end try