How to distinguish between label and fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 5
- Joined: Thu Sep 01, 2016 5:03 pm
How to distinguish between label and fields
I currently creating a script that will clear all values in all fields in each card of each stack. My problem is how will I distinguish if the control is a label or field so that I my script will not include labels during clearing. Is there a property or a way to differentiate labels and other fields?
Re: How to distinguish between label and fields
Labels are only fields with certain properties set, so the only way is to give all your fields and labels a distinctive name such as prefixing with fld or lbl respectively. You might look at the locktext property, this is set by default for a label. It may be useful but not definitive.
Re: How to distinguish between label and fields
Hi,
it's not set as default, but you can use the "cantselect" property to distinguish:
it's the small lock icon in the project browser, and setting this (true) for labels & clearing it (false = default) for fields actually suits the common workflow - you rarely need to interact with a label in a finished stack.
Have fun!
it's not set as default, but you can use the "cantselect" property to distinguish:
it's the small lock icon in the project browser, and setting this (true) for labels & clearing it (false = default) for fields actually suits the common workflow - you rarely need to interact with a label in a finished stack.
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to distinguish between label and fields
Hi. Setting up your label fields with some reliable property is a good method. The showBorder? Just for laughs, I made a label field and an editable field with the sane rect. In a button:
Looking at temp, (Your temp will have different locs, names and rect. That sort of thing) is there a reliable, and that is the key operative word, difference in properties that you can, er, rely on? I like the showBorder.
Craig Newman
Code: Select all
on mouseUp
put the properties of fld 1 into f1
put the properties of fld 2 into f2
combine f1 with return and comma
combine f2 with return and comma
repeat with y = 1 to the number of lines of f1
if line y of f1 <> line y of f2 then put line y of f1 && line y of f2 & return after temp
end repeat
end mouseUp
Craig Newman
Re: How to distinguish between label and fields
I've got into the habit of prefixing all my controls thus:
FldName
LblName
BtnName
GrpName
etc...
This way I find it easy in code to see what type of control I am referencing and also I can do a loop through all of the controls looking for the prefixes.
FldName
LblName
BtnName
GrpName
etc...
This way I find it easy in code to see what type of control I am referencing and also I can do a loop through all of the controls looking for the prefixes.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
-
- Posts: 5
- Joined: Thu Sep 01, 2016 5:03 pm
Re: How to distinguish between label and fields
Thank you very much for your feedback. I'm sorry I forgot to mention that I am assign to an existing project that was handled by a lot of programmer before me. Sad to say a lot of them does not follow our naming convention, that is why I was having a hard time finding ways to clear all fields in each card. The project has a lot of stacks containing a lot of controls. If I will change all controls name not to mention tracing the name in all codes, it will take me forever to finish this.
Is there a way we can distinguish if that control is a field or label by running a script?
Thanks in advance
Is there a way we can distinguish if that control is a field or label by running a script?
Thanks in advance
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: How to distinguish between label and fields
Hi
Just did a little test and its not what IO expected
i installed a button a textfield called "afield" and a label called "alablel" on my stack with the code as below.
I expected
I expected a list of properties being almost the same for a label and a text box -- NO cigar.
The 74 properties are exactly the same.
What I then did was made a best guess of what properties might be false in the majority of cases for a label than a field and I was correct unless
you have real UI problem where people travers onto labels.
So if you find all controls where the traversalon property is set to false I'm pretty sure they will be labels.
You might get a few textboxes set to false for some reason but it will be pretty few and far between.
The default style of a label is transparent but for a textbox it is rect so that could home in on all the labels.
Hope this helps.
As it is, I start the names of all my labels with lbl and field with "fld" or "txt" depending on wether the textbox is updateable by the user or via script
Regards Lagi
Just did a little test and its not what IO expected
i installed a button a textfield called "afield" and a label called "alablel" on my stack with the code as below.
Code: Select all
on mouseUp
local ff, ll
put the properties of field "afield" into ff
put the properties of field "alabel" into ll
put the keys of ff
put the keys of ll
end mouseUp
I expected a list of properties being almost the same for a label and a text box -- NO cigar.
The 74 properties are exactly the same.
What I then did was made a best guess of what properties might be false in the majority of cases for a label than a field and I was correct unless
you have real UI problem where people travers onto labels.
So if you find all controls where the traversalon property is set to false I'm pretty sure they will be labels.
You might get a few textboxes set to false for some reason but it will be pretty few and far between.
The default style of a label is transparent but for a textbox it is rect so that could home in on all the labels.
Hope this helps.
As it is, I start the names of all my labels with lbl and field with "fld" or "txt" depending on wether the textbox is updateable by the user or via script
Regards Lagi
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to distinguish between label and fields
Hi.
Do I understand that you only looked at the keys of each array? And did not check the values associated with each?
It is true that the "properties" of any kind of field are identical, but it is not true that the properties are. A little cute, but do you see what I mean?
Craig
Do I understand that you only looked at the keys of each array? And did not check the values associated with each?
It is true that the "properties" of any kind of field are identical, but it is not true that the properties are. A little cute, but do you see what I mean?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: How to distinguish between label and fields
A label is a non-editable field. Lots of other ways to handle this too, but that one distinction is simple and universal; see the lockText property.
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
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: How to distinguish between label and fields
Hi
This was a start
I specifically didn't mention lock text because I use that a lot in my programs to stop users accidentally editing
Records without specifically pressing an edit button
I'm sure there are other properties but I would guess those two would cover 99% of the cases
Would have been easier if ther was a propert on all objects saying what they were though
Lagi
This was a start
I specifically didn't mention lock text because I use that a lot in my programs to stop users accidentally editing
Records without specifically pressing an edit button
I'm sure there are other properties but I would guess those two would cover 99% of the cases
Would have been easier if ther was a propert on all objects saying what they were though
Lagi
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to distinguish between label and fields
There is. The "properties". we both spoke of that above. What would you like to see in such a gadget that is not already there?Would have been easier if ther was a propert on all objects saying what they were though
Craig
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: How to distinguish between label and fields
I can't see any property that's is either specific to
A label or a text box -- they are all the same. I was talking of s property maybe
Named say objtype that the system sets to Txtfield or lstbox Or lblfield etc. It's not really a problem
If you have a naming convention but as the op said ... he has inherited crud.
Which property did you mean Craig that already exists?
Lagi
A label or a text box -- they are all the same. I was talking of s property maybe
Named say objtype that the system sets to Txtfield or lstbox Or lblfield etc. It's not really a problem
If you have a naming convention but as the op said ... he has inherited crud.
Which property did you mean Craig that already exists?
Lagi
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to distinguish between label and fields
When I need that, my method is to set 'the type' of a field, a customProperty: one of "label,list,text,whatever".
This is an easy to remember customProperty if a resetting is needed whenever the "type/style" of the field changes.
This is an easy to remember customProperty if a resetting is needed whenever the "type/style" of the field changes.
Code: Select all
set type of fld 1 to "label"
if the type of fld 1 is "label" then do empty
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to distinguish between label and fields
I did not mean that there was a unique property that only label fields have. There are none. They are, as Sparkout mentioned, just fields, the same object class as, er, fields. So you must manage any reliable distinction yourself. Naming conventions, reliable differences (properties) between label fields and all other fields, a custom property, as Hermann suggested, whatever.Which property did you mean Craig that already exists?
Perhaps the showBorder is not really reliable, as I had mentioned above (this was before we knew that you had inherited the work of others). In any case, you will have to find every field and assign some characteristic that distinguishes only label fields. This should not be too onerous, needs only be done once, and then you follow that convention going forward.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to distinguish between label and fields
If using locktext isn't enough you can check for three properties that all labels have:
locktext = true
autohilite = false
traversalon = false
A field that has all three of these property values is likely to be a label. There are exceptions, a locked field with the last two properties set to true allows the text to be selected and copied but not changed. This is fairly rare though.
locktext = true
autohilite = false
traversalon = false
A field that has all three of these property values is likely to be a label. There are exceptions, a locked field with the last two properties set to true allows the text to be selected and copied but not changed. This is fairly rare though.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com