setting a behavior with out using an ID

Peter M. Brigham pmbrig at gmail.com
Tue Oct 28 09:36:51 EDT 2014


Coming in late on this (at a conference for 3 days) but I have a couple of virtual property handlers that address some of these issues. The robustID getProp returns the kind of string that behavior references need.

--------

getProp robustID
   ----  a virtual property  ----
   -- getting the long id of a control can result in different values depending on
   --    (a) where the stack is stored on the user's disk and
   --    (b) which card is the currentcard when the property is fetched
   -- the robustID is consistent no matter what card is current
   --    and no matter which folder the user has stored the stack in;
   -- format: button id 1039 of bkgnd id 1003 of stack "subStack1"
   --            of stack "tMainStack"
   -- the robustID can be used as a complete object reference,
   --    just like the long ID
   
   -- requires q()
   
   put the long id of the target into tLongID
   if tLongID begins with "stack" then
      return the name of tLongID
   end if
   
   replace " stack " with cr in tLongID
   put line -1 of tLongID into mainStackFileName
   replace quote with empty in mainStackFileName
   put the short name of stack mainStackFileName into mainStackName
   put q(mainStackName) into line -1 of tLongID
   replace cr with " stack " in tLongID
   
   replace " of " with cr in tLongID
   put lineoffset(cr &"card ",cr & tLongID) into cdLineNbr
   if cdLineNbr > 1 then delete line cdLineNbr of tLongID
   replace cr with " of " in tLongID
   
   replace "group" with "bkgnd" in tLongID
   -- in case the group is not placed on the currentcard
   return tLongID
end robustID

getProp robustName
   ----  a virtual property  ----
   -- getting the long name of a control can result in different values depending on
   --    (a) where the stack is stored on the user's disk and
   --    (b) which card is the currentcard when the property is fetched
   -- the robustName is consistent no matter what card is current
   --    and no matter which folder the user has stored the stack in;
   -- format: button "copyText" of bkgnd "fieldGp" of stack "substack1"
   --            of stack "myMainStack"
   -- the robustName can be used as a complete object reference,
   --    just like the long name
   
   -- requires q()
   
   put the long name of the target into tLongName
   if tLongName begins with "stack" then
      return the name of tLongName
   end if
   
   replace " stack " with cr in tLongName
   put line -1 of tLongName into mainStackFileName
   replace quote with empty in mainStackFileName
   put the short name of stack mainStackFileName into mainStackName
   put q(mainStackName) into line -1 of tLongName
   replace cr with " stack " in tLongName
   
   replace " of " with cr in tLongName
   put lineoffset(cr & "card ", cr & tLongName) into cdLineNbr
   if cdLineNbr > 1 then delete line cdLineNbr of tLongName
   repeat with c = 1 to the number of lines of tLongName
      put line c to -1 of tLongName into ctrlName
      replace cr with " of " in ctrlName
      put the name of ctrlName into line c of tLongName
   end repeat
   replace cr with " of " in tLongName
   
   replace "group" with "bkgnd" in tLongName
   -- in case the group is not placed on the currentcard
   return tLongName
end robustName

function q str
   -- quote
   -- place this handler in a library stack,
   --     where it will be available everywhere
   return quote & str & quote
end q

----------

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Oct 25, 2014, at 3:48 PM, Peter Haworth wrote:

> Doesn't address your issue, but I do have a free stack that is useful if
> you need to make wholesale changes to a behavior id.  You can search for
> all objects with a string in the behavior and replace it with another.
> 
> If interested, its available at http://www.lcsql.com/free-stuff.html
> 
> Pete
> lcSQL Software <http://www.lcsql.com>
> Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
> SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
> 
> On Wed, Oct 22, 2014 at 7:31 PM, Todd Geist <todd at geistinteractive.com>
> wrote:
> 
>> Hello,
>> 
>> I don’t like to use IDs to reference Objects.  But it seems that the only
>> way you can reference a Behavior is with it’s ID. Is that true?  Is there
>> another way?
>> 
>> Thanks
>> 
>> Todd
>> _______________________________________________
>> 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
> _______________________________________________
> 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