renaming a group
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
renaming a group
Hi all,
How do I rename a group? I've got the following code which selects the fields on a layout, then groups them but I need to rename that group into something more meaningful. So far I have tried the following
---
//attempt 1
group "grp_card1"
---
//attempt 2
group
set the name of group to "grp_card1"
--
//attempt 3
group
set the name of last group to "grp_card1"
// This renames an group I pasted in before I selected objects to be in my new group
--
//attempt 4
group
set the name of it to "grp_card1"
I've run out of other ideas/concepts to try. I'm using the keyword group to group my objects, whats the next line of code I need to change the name of the newly created group into something more meaningful.
Many thanks
Jalz
How do I rename a group? I've got the following code which selects the fields on a layout, then groups them but I need to rename that group into something more meaningful. So far I have tried the following
---
//attempt 1
group "grp_card1"
---
//attempt 2
group
set the name of group to "grp_card1"
--
//attempt 3
group
set the name of last group to "grp_card1"
// This renames an group I pasted in before I selected objects to be in my new group
--
//attempt 4
group
set the name of it to "grp_card1"
I've run out of other ideas/concepts to try. I'm using the keyword group to group my objects, whats the next line of code I need to change the name of the newly created group into something more meaningful.
Many thanks
Jalz
Re: renaming a group
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:21 pm, edited 1 time in total.
shiftLock happens
Re: renaming a group
Hi.
There is an anomaly (bug?) in LC that makes the "last" keyword unstable with groups. It works fine for all other objects. There are several threads about this, going back a year or three. Check the user notes in the dictionary under the "last" keyword. (they are mine).
So it is perfectly fine to say:
set the name of the last field to "myLastField"
where that field might have been created, say, under script control. But you cannot trust:
set the name of the last group to "myLastGroup"
The best way out of this is to name the templateGroup. The "last" group thus formed will take that property, and that is how you can isolate it and deal with it as you wish. Of course, you should change the name of that last group, so that any subsequently created groups will be able, in their turn, to be identified in the same way.
Write back if none of this makes sense.
Craig Newman
There is an anomaly (bug?) in LC that makes the "last" keyword unstable with groups. It works fine for all other objects. There are several threads about this, going back a year or three. Check the user notes in the dictionary under the "last" keyword. (they are mine).
So it is perfectly fine to say:
set the name of the last field to "myLastField"
where that field might have been created, say, under script control. But you cannot trust:
set the name of the last group to "myLastGroup"
The best way out of this is to name the templateGroup. The "last" group thus formed will take that property, and that is how you can isolate it and deal with it as you wish. Of course, you should change the name of that last group, so that any subsequently created groups will be able, in their turn, to be identified in the same way.
Write back if none of this makes sense.
Craig Newman
Re: renaming a group
Hi Craig,
Yes, I think I'm coming across that bug. I cant rely on the command
set the name of the last group to "myLastGroup" as that is renaming another group on my layout, and I have several grouped objects.
What I want to do in a script is select all objects and then simply group and then name that group. I've got everything apart from renaming the group.
I have not really looked into templateGroup, so didn't quite understand your solution - yet. I'll try and see if I can find some info in the forums. Pity LC has this anomaly, as the info I found, set the name of the last group to "myLastGroup" seemed to be the answer.
Thanks
Jalz
Yes, I think I'm coming across that bug. I cant rely on the command
set the name of the last group to "myLastGroup" as that is renaming another group on my layout, and I have several grouped objects.
What I want to do in a script is select all objects and then simply group and then name that group. I've got everything apart from renaming the group.
I have not really looked into templateGroup, so didn't quite understand your solution - yet. I'll try and see if I can find some info in the forums. Pity LC has this anomaly, as the info I found, set the name of the last group to "myLastGroup" seemed to be the answer.
Thanks
Jalz
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: renaming a group
Craig, that sounds like a bug to me. Did you file a report?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: renaming a group
It may not be a bug if there is a background group in place, where the last group would be the background one. If that's the case then asking for the "last card group" instead of just the "last group" should work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: renaming a group
Craig,
if you file a bug report could you propose that Livecode returns the group involved in "group" in the it variable. Analoguous to "create".
Or is there something I am missing that prevents LC to put the long id of the group that groups into it?
Kind regards
Bernd
if you file a bug report could you propose that Livecode returns the group involved in "group" in the it variable. Analoguous to "create".
Or is there something I am missing that prevents LC to put the long id of the group that groups into it?
Kind regards
Bernd
Re: renaming a group
Hi all,
Just thought I'd recreate a dummy card with objects and a script similar to the one I am working on so you guys can verify whether its a bug or me. I was trying to group all the objects and then put a v scrollbar around the group. Notice how it groups everything as it should, but renames a different group when I use the set name ..last... command.
Thanks
Jalz
Just thought I'd recreate a dummy card with objects and a script similar to the one I am working on so you guys can verify whether its a bug or me. I was trying to group all the objects and then put a v scrollbar around the group. Notice how it groups everything as it should, but renames a different group when I use the set name ..last... command.
Thanks
Jalz
- Attachments
-
- mygroup.livecode.zip
- (1.39 KiB) Downloaded 176 times
Re: renaming a group
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens
Re: renaming a group
Hi Jalz,
either do as Hermann suggest with the highest group (did not try this) or do as I suggest look for the highest ID of all group and that should be the one just created to group your groups.
Kind regards
Bernd
either do as Hermann suggest with the highest group (did not try this) or do as I suggest look for the highest ID of all group and that should be the one just created to group your groups.
Code: Select all
on mouseUp
repeat with x = 1 to the number of controls
put "field,button,graphic,image" into tObjects
put the long id of control x into tLong
if tLong contains "group" AND word 1 of tLong is among the items of tObjects then
next repeat
else
set the selected of the long id of control x to true
end if
end repeat
group
-- get the highest id of groups, since "group" created a new group that is the one we are looking for
repeat with i = 1 to the number of groups of this card
put the short id of group i & comma after tCollect
end repeat
delete last char of tCollect -- a return
put max (tCollect) into tHighestID -- here we extract the highest id
set the name of group id tHighestID to "grp_card1"
set the vScrollbar of group "grp_card1" to true
end mouseUp
Bernd
Re: renaming a group
This is going on way too long:
Sorry Craig.
Now in your stack that header is wide so you wont see the vertical scrollbar unless you increase the size of the stack.
Now from this is the "template object", just about everything has one and it is used when "create" or in this case "group" is used. New objects are created using their "template", so you just set it up before making the new object.
Easy yes?
Simon
Code: Select all
set the name of the templateGroup to "Misery"
group
--set the name of the last group to "grp_card1"
set the vScrollbar of group "Misery" to true
Now in your stack that header is wide so you wont see the vertical scrollbar unless you increase the size of the stack.
Now from this is the "template object", just about everything has one and it is used when "create" or in this case "group" is used. New objects are created using their "template", so you just set it up before making the new object.
Easy yes?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: renaming a group
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens
Re: renaming a group

Bernd, your code looking for the highest grouped number and then applying a scrollbar also seems to work
Last edited by jalz on Mon Jun 16, 2014 11:27 pm, edited 1 time in total.
Re: renaming a group
Hi jalz,
No Worries, you've sparked an interesting conversation, without it I would never have seen Craig's post. Now it's stuck in my head for something to watch out for.
Simon
No Worries, you've sparked an interesting conversation, without it I would never have seen Craig's post. Now it's stuck in my head for something to watch out for.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: renaming a group
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:20 pm, edited 1 time in total.
shiftLock happens