The selectedObjects - is it a container or not?

Graham Samuel livfoss at mac.com
Wed Apr 19 08:14:01 EDT 2017


Yes, thanks very much Mark. I do get it completely now, if a little belatedly!

Cheers

Graham

> On 19 Apr 2017, at 09:15, Mark Waddingham via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi Graham,
> 
> On 2017-04-17 21:07, Graham Samuel via use-livecode wrote:
>> I have a stack where the user is allowed to select vector objects. For
>> this example, let’s assume some objects are already selected.
>> I am using LC 8.1.4 rc1 on a Mac running Sierra, and I  have a bit of
>> code that says in part:
>>    if the selectedObjects is not empty then
>>      repeat with i = 1 to the number of lines of the selectedObjects
>>> 
> Just to clear up precisely what is going on here...
> 
> There are a number of pieces of syntax in LiveCode which return control
> references (e.g. field 1). As LiveCode represents such things as strings
> there is an ambiguity when you do:
> 
>  <something text related> of <syntax returning control reference>
> 
> e.g. the number of lines of the selectedObject
> 
> In this case it could either mean:
> 
>  1) the number of lines in the string returned by the selectedObject
> 
>  2) the number of lines in the control returned by the selectedObject
> 
> The engine tends towards case (2) in most cases (I can't say all cases
> without going through all such things and checking) - including this one.
> 
>> OTOH, if I change the second line to
>>     repeat with i = 1 to the number of lines of (the selectedObjects0
>> the code works as expected.
> 
> The presence of brackets here force evaluation of 'the selectedObjects'
> as a string and not as a control.
> 
>> If I execute in the message box:
>>   put the number of lines of the selectedObjects
>> I sometimes get no result and sometimes “source is not a container”,
>> but if I change the line to:
>>    put the number of lines of (the selectedObjects)
>> I always get the right answer.
> 
> In the first case, whether or not 'the number of lines of the selectedObjects'
> will do something sensible depends on:
> 
>  1) if there is a selectedObject (otherwise you are trying to get the
>     number of lines in no object - which makes no sense)
> 
>  2) There is a selected object, but it has no idea of a 'text' property
>     so doesn't have anything for 'the number of lines of' to process.
> 
> Hope this helps!
> 
> Mark.
> 
> -- 
> Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
> LiveCode: Everyone can create apps
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list