how to get the value of a custom property if the name of the cProperty is in a variable?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
Hi,

let´s say a card has a custom property name cMyProp.

The variable tMyVar contains the word “cMyProp”

How do i get the value of the custom property using the variable tMyVar?

Regards,
Matthias



Matthias Rebbe
+49 5741 310000
‌matthiasrebbe.eu <http://matthiasrebbe.eu/>‌

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
Hi Matthias,

> Am 02.08.2017 um 19:20 schrieb Matthias Rebbe via use-livecode <[hidden email]>:
>
> Hi,
>
> let´s say a card has a custom property name cMyProp.
> The variable tMyVar contains the word “cMyProp”
> How do i get the value of the custom property using the variable tMyVar?

...
answer the tMyVar of this cd
...
:-)

> Regards,
> Matthias

Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
Thanks Klaus

Tried your  suggestion already before posting, but that did not work. Therefore I thought i have to use value or so.

But i just had a “little” error in my script. I should check my code twice before asking.

Thanks again.

Matthias





Matthias Rebbe
+49 5741 310000
‌matthiasrebbe.eu <http://matthiasrebbe.eu/>‌

> Am 02.08.2017 um 19:25 schrieb Klaus major-k via use-livecode <[hidden email] <mailto:[hidden email]>>:
>
> Hi Matthias,
>
>> Am 02.08.2017 um 19:20 schrieb Matthias Rebbe via use-livecode <[hidden email] <mailto:[hidden email]>>:
>>
>> Hi,
>>
>> let´s say a card has a custom property name cMyProp.
>> The variable tMyVar contains the word “cMyProp”
>> How do i get the value of the custom property using the variable tMyVar?
>
> ...
> answer the tMyVar of this cd
> ...
> :-)
>
>> Regards,
>> Matthias
>
> Best
>
> Klaus
>
> --
> Klaus Major
> http://www.major-k.de <http://www.major-k.de/>
> [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On Wed, Aug 2, 2017 at 10:25 AM, Klaus major-k via use-livecode <
[hidden email]> wrote:

>
> answer the tMyVar of this cd
>

This is an area that is awkward in live code.

The use of unquoted literals for this is inconsistent with most of live
code (but quoting would be inconsistent with the built in properties, so .
. .)

I have "loops" like

repeat for each word someProp in "theOnlyPropInTheList"

set the someProp of someControl to myVal

end repeat


If you have a variable whose name is the same as the property, there does
does not seem to be a good solution.
--
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
A good reason to use consistent prefixes to distinguish custom props and
variables perhaps.
On Wed, 2 Aug 2017 at 20:56, Dr. Hawkins via use-livecode <
[hidden email]> wrote:

> On Wed, Aug 2, 2017 at 10:25 AM, Klaus major-k via use-livecode <
> [hidden email]> wrote:
>
> >
> > answer the tMyVar of this cd
> >
>
> This is an area that is awkward in live code.
>
> The use of unquoted literals for this is inconsistent with most of live
> code (but quoting would be inconsistent with the built in properties, so .
> . .)
>
> I have "loops" like
>
> repeat for each word someProp in "theOnlyPropInTheList"
>
> set the someProp of someControl to myVal
>
> end repeat
>
>
> If you have a variable whose name is the same as the property, there does
> does not seem to be a good solution.
> --
> Dr. Richard E. Hawkins, Esq.
> (702) 508-8462
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
You can put the name of the property into a local var and use that (unless I misunderstood the problem).

Ali's suggestion is however the very pragmatic one - there are always going to be cases where var names might conflict with other things 'in context' and require disambiguation. (Although even that doesn't work in some cases - consider 'tExt' - when you have case insensitivity and no need to explicitly declare variables).

Of course, if you'd like to file a bug report / enhancement about being able to do 'the "mycustompropname" of ... - then that is probably the 'future' much better solution :)

Warmest Regards,

Mark.

Sent from my iPhone

> On 2 Aug 2017, at 21:56, Dr. Hawkins via use-livecode <[hidden email]> wrote:
>
> On Wed, Aug 2, 2017 at 10:25 AM, Klaus major-k via use-livecode <
> [hidden email]> wrote:
>
>>
>> answer the tMyVar of this cd
>>
>
> This is an area that is awkward in live code.
>
> The use of unquoted literals for this is inconsistent with most of live
> code (but quoting would be inconsistent with the built in properties, so .
> . .)
>
> I have "loops" like
>
> repeat for each word someProp in "theOnlyPropInTheList"
>
> set the someProp of someControl to myVal
>
> end repeat
>
>
> If you have a variable whose name is the same as the property, there does
> does not seem to be a good solution.
> --
> Dr. Richard E. Hawkins, Esq.
> (702) 508-8462
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
On Wed, Aug 2, 2017 at 2:36 PM, Mark Waddingham via use-livecode <
[hidden email]> wrote:

> You can put the name of the property into a local var and use that (unless
> I misunderstood the problem).
>

That's what I do

>
>
> Of course, if you'd like to file a bug report / enhancement about being
> able to do 'the "mycustompropname" of ... - then that is probably the
> 'future' much better solution :


I've given thought to that on and off--but I don't see a way thats both
consistent with specifying a text string, and with the usage for other
objects.

Oh, wait; now I remember:  allow the use of quoted text in the property
reference.  At the moment,

the "catness" of control "dog"

refers not to the catness property, but to a property whose name begins
with a quote.  I think that *this* is an inconsistency and a bug.

OK, filed as *Bug 20228* <http://quality.livecode.com/show_bug.cgi?id=20228>
 - quotes taken as literal rather than as a delimiter when referring to
custom properties
--
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
>
> let´s say a card has a custom property name cMyProp.
>
> The variable tMyVar contains the word “cMyProp”
>
> How do i get the value of the custom property using the variable tMyVar?

Using the “do” command, a quick test and this works OK:

        on mouseUp
                put "cMyProp" into tMyVar

                do "put the" && tMyVar && "of this card into fld 1"

        end mouseUp


Paul
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode

> On 3 Aug 2017, at 7:36 am, Mark Waddingham via use-livecode <[hidden email]> wrote:
>
> Of course, if you'd like to file a bug report / enhancement about being able to do 'the "mycustompropname" of ... - then that is probably the 'future' much better solution :)

Er… why if you know the name wouldn’t you type it unquoted? Are you really suggesting to put any expression there? The property/function ambiguity with `the` will make our heads explode!

Cheers

Monte
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
On Wed, Aug 2, 2017 at 8:39 PM, Monte Goulding via use-livecode <
[hidden email]> wrote:

>
> Er… why if you know the name wouldn’t you type it unquoted? Are you really
> suggesting to put any expression there? The property/function ambiguity
> with `the` will make our heads explode!
>

If I have a variable "propertyZ", then under current code I *cannot* use

   set the propertyZ of theThing to 7

to affect the custom property named propertyZ.  Allowing quotes would solve
this.

In my case, I hit this in a "metaprocedure" that runs in development to
enforce consistency, find variable fields, and whathaveyou, and separately
came to the same "natural" name for both a variable and a customproperty,
leading to significant debugging until I figured out why it wasn't working.



--
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
If the handler is in the same script as the constant, why would you? A constant is for representing values that do not change after compile. Variables are for values that change during runtime. I cannot imagine a use case for putting a constant name into a variable, although I have thought about the need to get the constant from another script, until I remembered it's just easier to set a custom property.

In fact (I think I've said so before) custom props are a great way to mimic scoped variables, and even constants. For instance all my datagrids have a property tablename containing the name of the table I query to populate it.

Bob S


> On Aug 2, 2017, at 10:20 , Matthias Rebbe via use-livecode <[hidden email]> wrote:
>
> Hi,
>
> let´s say a card has a custom property name cMyProp.
>
> The variable tMyVar contains the word “cMyProp”
>
> How do i get the value of the custom property using the variable tMyVar?
>
> Regards,
> Matthias
>
>
>
> Matthias Rebbe

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get the value of a custom property if the name of the cProperty is in a variable?

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On 2017-08-03 05:39, Monte Goulding via use-livecode wrote:
> Er… why if you know the name wouldn’t you type it unquoted? Are you
> really suggesting to put any expression there? The property/function
> ambiguity with `the` will make our heads explode!

For the reason Dr Hawkins originally asked about ;)

There is no ambiguity if we have:

    1. 'the' IDENTIFIER 'of' ...
    2. 'the' STRING 'of' ...
    3. 'the' '(' EXPRESSION ')' 'of' ...

The key thing about making property syntax more flexible (e.g. multiple
words - unquoted) is to enforce 'the' and 'of' - indeed, if you use a
custom (non engine keyword) name of any kind then both are required so
that's good :)

In any case, I got around to looking at it this morning and case (2)
almost works already. Doing:

   set the "catness" of this stack to "very"

   put the customKeys of this stack

   put the "catness" of this stack

Results in a catness (no quotes) key in the stack's custom properties,
but an execution error (source is not a container) when evaluating it.

Warmest Regards,

Mark.

--
Mark Waddingham ~ [hidden email] ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...