universally changing the name of an object

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

universally changing the name of an object

Post by churchken » Sun Apr 29, 2007 5:14 am

Hi,

When the name of an object on a card is changed, could that name change be "automatically applied" to every instance where that object has been used in all scripts within all stacks of the currently open program?

It would appear that the "find and replace" option of the edit menu could do this, but not "automatically" at the time the name of an object is being changed. By linking the name change to be made to the specific object involved, there would be no need to "search" all text, labels, etc.

I'm not aware of any "down side" to this approach -- please let me know of some obvious reason to avoid doing this. ( or perhaps it could be made an "option" by the user )

Thanks for the consideration.
Ken

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Apr 29, 2007 9:12 am

Hi Ken,

If you change the label of an object instead of its name, there is no need to change anything in the scripts.

There is the Find & Replace utility in the Edit menu. This should allow you to find all instances of a string in all scripts.

Of course, it is possible to write a script that changes all instances of the name of a particular object, but I don't think this is a good idea, especially for larger projects that use more than 1 stackfile.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: universally changing the name of an object

Post by marielle » Sun Apr 29, 2007 10:58 am

The problem is that there is no reliable way to do this. Imagine the following scenario: Two objects can bear the same name. If you copy and paste an object, for instance, the copied object will have the same name as the original one. What would you expect to happen if the name of the second object, the copied one got changed?

What is unique to each object is it's id. You can gain the advantages you are after by referring, in your script to 'field id 1200' rather than 'field "myField"'. You are then free to change the object name as often as you want without impacting on your code.

Using ids of course doesn't make for easy to read code. This can be addressed by using the following each time you need the object

Code: Select all

put the short name of field id 1200 into myField
put the width of field myField (no quotes here, you refer to a variable)
....
put the name of field id 1200 into myField
put the width of myField (my Field includes both object type and object name)
....
put the long id of field id 1200 into myField
put the width of myField (my field holds a full reference to the object, that includes the object type)
(use a meaningful name in place of myField, otherwise, this defeats the purpose)
Last edited by marielle on Sun Apr 29, 2007 10:53 pm, edited 1 time in total.

churchken
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 66
Joined: Sun Apr 15, 2007 2:54 pm

thanks

Post by churchken » Sun Apr 29, 2007 7:40 pm

Mark & Marielle

Thanks for your comments ---

The "find & replace" edit menu looks to be the most straight forward approach and I'll stick with that.

Regards,
Ken

Post Reply