How to get the number of lines of a fld referenced by long ID in a variable.

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

How to get the number of lines of a fld referenced by long ID in a variable.

Richmond Mathewson via use-livecode
I'm trying to set up a global text only library that includes text handlers for formatting text run time.

Typical use case is : clickable list field with titles that wrap. Say you set type size to 16, text height to 20, dontWrap is false, first indent -40, left margin 20. This looks fine, but the lines are too close together.. Since there is no way to apply "spaceBelow" to a field…you have to dynamically run a script to "set the type" of each line run time after loading the field.

So far so good until this

# card script

put tTitles into fld "audioList"  # contains 30 lines
addSpaceBelowListLines (the long id of fld "audioList"),10


lib_SivaSivaMedia # a global "backscript" -- one of many

on addSpaceBelowListLines pField,pSpace
    put the number of lines of pField
# returns 1 --
# --  of course, that's a prop of the var, not the object it refes to

     repeat with x = 1 to (the number of lines of pField)
          set the spacebelow of line x of pField to pSpace
     end repeat
end addSpaceBelowListLines

# only line 1 gets added space.

In the msg box I can test

put the number of lines of (the long id of fld "audioList")
[return] 30

but

put the number of lines of pField = 1

# ok I get it a var,  single string, 1 line only

of course we can add to the card script

put tTitles into fld "audioList"
put the number of lines of tTitles into pLineCount
addSpaceBelowListLines (the long id of fld "audioList"), pLineCount, 10

LIBRARY:

on addSpaceBelowListLines pField, pLineCount, pSpace
repeat with x = 1 to pLineCount
          set the spacebelow of line x of pField to pSpace
     end repeat
end addSpaceBelowListLines

And this works.. it even has an interesting visual effect as the lines layout dynamically in front of the users, spreading out top to bottom.
( though I probably should lock and unlock the screen for small devices speed)

But that it would be nice not be "stuck" with only finding out the properties of the variable as a variable.

i.e. pField is a variable with 1 line…

but  to be able to address the properties of the object referred to by a variable containing the long ID of an object/

How do we do that?

BR




_______________________________________________
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 number of lines of a fld referenced by long ID in a variable.

dunbarx
Hi.

You need a "do" construction to, er, deconstruct the "contents" of the variable to the object reference of that variable. Do you know how to do this?

Craig Neman
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to get the number of lines of a fld referenced by long ID in a variable.

Richmond Mathewson via use-livecode
Change it to "the number of lines in the text of pfield" and it should work.

On Wed, Jun 28, 2017 at 8:59 PM, dunbarx via use-livecode <
[hidden email]> wrote:

> Hi.
>
> You need a "do" construction to, er, deconstruct the "contents" of the
> variable to the object reference of that variable. Do you know how to do
> this?
>
> Craig Neman
>
>
>
> --
> View this message in context: http://runtime-revolution.
> 278305.n4.nabble.com/How-to-get-the-number-of-lines-of-a-
> fld-referenced-by-long-ID-in-a-variable-tp4716341p4716343.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> 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 number of lines of a fld referenced by long ID in a variable.

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
On 6/28/17 9:25 PM, Sannyasin Brahmanathaswami via use-livecode wrote:

> on addSpaceBelowListLines pField,pSpace
>      put the number of lines of pField
> # returns 1 --
> # --  of course, that's a prop of the var, not the object it refes to
>
>       repeat with x = 1 to (the number of lines of pField)
>            set the spacebelow of line x of pField to pSpace
>       end repeat
> end addSpaceBelowListLines
>
> # only line 1 gets added space.


Try this, assuming pField is a long ID:

on addSpaceBelowListLines pField,pSpace
     set the spaceBelow of line 1 to -1 of pField to pSpace
end addSpaceBelowListLines


--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
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 number of lines of a fld referenced by long ID in a variable.

Richmond Mathewson via use-livecode
In reply to this post by Richmond Mathewson via use-livecode
Sannyasin Brahmanathaswami wrote:

 > But that it would be nice not be "stuck" with only finding out the
 > properties of the variable as a variable.
 >
 > i.e. pField is a variable with 1 line…
 >
 > but  to be able to address the properties of the object referred to by
 > a variable containing the long ID of an object/
 >
 > How do we do that?

By addressing properties using property syntax.

A field is an object; the text of a field is a property of the object.

If you adopt a habit of referring to properties using property syntax
the ambiguity goes away, e.g.:

    get line 2 of the text of pField

How did we get to this "sometimes" rule, where referring to an object
sometimes refers to the object itself and other times refers to one
specific property of the object, its text?

Thank the mother tongue, HyperTalk.  For reasons not entirely unsound
for an authoring system, they recognized that a field's text property is
the most commonly accessed property.  So to provide a certain level of
syntactic simplicity they allowed us to use an object reference in cases
where what we really mean is the value of that one property of the object:

    put field 1 + field 2 into field 3

..is certainly more fun to write than:

   set the text of field 3 to the text of field 1 + the text of field 2

Seems so natural to use the shorter form, and indeed that first line
above is included in my introductory lesson when I teach this family of
languages.

But that syntactic simplicity comes at a cost.  Everything in an
imperfect universe involves trade-offs; nothing is a magic pony.  Here
the trade-off for syntactic simplicity is cognitive load down the road
from the ambiguity introduced by this implicit property access.

It causes confusion for even folks who've been scripting in these
languages for decades, evidenced in this thread. :)

So very soon after the seductive quality of referring to a field's text
property by using a reference to the field object has the learner
hooked, I introduce the text property, along with other properties, and
suggest using property syntax where practical, esp. when the object
reference is in a variable*.

Yes, the rules that distinguish when an object reference will actually
refer to the object and when an object reference will implicitly refer
to the value of one specific property of the object are knowable, likely
documented, and ultimately teachable.

But all these years later it still causes confusion now and then, so I
try to avoid the ambiguity with a habit of referring to the text
property using the same syntax I'm expected to use for any other
property, at least when the object reference is in a variable.

When using a hard-wired object reference it rarely matters at all.  But
the moment I'm referring to an object in a variable, I either need to
remain mindful of the implications of this language ambiguity or simply
stick to the pattern of referring to object properties using property
syntax.



* Insanely OCD tidbit:  Most of the time when I store an object
reference in a variable I do so using the object's long ID.  It's
absolute and unambiguous, and doing that consistently means I don't need
to think as much.

To remind myself that I'm using the long ID, I've adopted a habit of
using the variable name tObj.  I use it a lot, and it's short so it's
easy to type.

This distinguishes it from those exceptional cases where I might use
just the short name of an object, like a field name, where I'll use
something like tFieldName.  With that, years later I can readily see
that it's not how I most commonly do things, and describes the form the
variable contains within the variable name.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
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...