How to create a new label field programmatically?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Wed May 08, 2019 6:48 pm

More than just theory, those are the differences (video in last post).
richmond62 wrote:
Wed May 08, 2019 6:40 pm
( can't see a difference in terms of the border )
The 'field' and 'label' both have a border by default, the field additionally has 'show border' checked, the label does not. Once it is checked, they are identical.
also wonder about "transversal"; must remember to set LGBT to true.
You can substitute 'focusable' for 'transversal' (they did in the default labeling for the PI) if it makes you feel more comfortable :D

I made the label below from the field above in this screen shot. Mc really makes it easier to discern what came from what in most cases, you can see there is no 'label' object anywhere back then.
Selection_001.png
I believe its magic magic...
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Wed May 08, 2019 9:02 pm

Bogs.

Right you are. I made my own list of properties early on, and simply ignored that one. I never thought the "autohilite" was pertinent in terms of allowing a label field to be editable. The dictionary says;
Specifies whether a button highlights when it's pressed, or whether selected text in a field is highlighted.
I didn't need the properties to know to clear "lockText". Reading the dictionary entry again, I would have still ignored autoHilite.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Wed May 08, 2019 9:49 pm

Yah, it isn't the clearest definition going on out there :D

The two lists of properties were more for someone with far less time and knowledge in Lc than you who may stumble across this later. Well, that, and it is easier for me to compare lists and get differences than sometimes comparing panels where I might miss something :twisted:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Thu May 09, 2019 2:43 am

I have several times, for this or that reason, gotten the properties of two objects and written a handler to separate the values that either do not appear in each, or are different in each.

This gadget would not have helped me here, since I would not have tested that particular property in that context. I was not being thorough.

Really. The autoHilite?

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Thu May 09, 2019 11:00 am

dunbarx wrote:
Thu May 09, 2019 2:43 am
This gadget would not have helped me here, since I would not have tested that particular property in that context. I was not being thorough.
And that shows how little I know in comparison, I don't have the knowledge to make the comparison based on assumptions from years of experience in playing around with this language, so I compared the lines against each other and made note of the major differences (I dropped every one that wasn't a match), and it makes for a very short list.

autoHilite makes sense in this context to me because of what happens to a button when it isn't checked, the button acts 'frozen'. I just made the leap to the field acting the same way because of something I read elsewhere, which is that a locked field can act like a button only if it is completely locked.

Now I wonder where I was reading that from. Hmmm.
Selection_001.png
Enlightening...
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Thu May 09, 2019 2:27 pm

Bogs.
a locked field can act like a button only if it is completely locked.
Well, yes, in that a locked field will receive "mouseUp" messages.

I am happy to know, again, that within LC object types, the differences are only in their properties, and you can transform one into another. The greatest leap in that sort of thinking is to change an ordinary button into a combo box. :wink:

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to create a new label field programmatically?

Post by bogs » Thu May 09, 2019 3:14 pm

dunbarx wrote:
Thu May 09, 2019 2:27 pm
The greatest leap in that sort of thinking is to change an ordinary button into a combo box. :wink:
I'm just happy that someone else figured out and implemented it all so I don't have to :wink:
Image

xpaceone
Posts: 1
Joined: Tue Sep 29, 2020 1:53 pm

Re: How to create a new label field programmatically?

Post by xpaceone » Tue Sep 29, 2020 7:19 pm

What I need to do is create a module which defines a new fieldable entity, called 'Company'. I have a list of, let's say, 20 fields that need to be filled out by each Company instance. These questions are predefined and some may contain custom validation.

At the moment, I'm at the point when I can add new fields to the Company entity. This works fine at the moment. My issue is that I need all these fields to be there as soon the module is installed, so adding them via the interface isn't an option.

I was wondering how can I approach this? I'd assume it comes down being able to do what can be done using the 'Manage Fields' UI programmatically.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Tue Sep 29, 2020 10:20 pm

Hi.

Not sure what you mean by:
My issue is that I need all these fields to be there as soon the module is installed, so adding them via the interface isn't an option.
Wouldn't you have, say, a card with all twenty or so fields already resident? Do you need to add or delete fields depending on the path that the user takes in filling them in? In any case all of this is straightforward. Fields can be created or deleted as needed, or hidden or shown if that makes more sense. They can be named, sized, colored and positioned, whatever, as well, based on rules you set.

If any of this is pertinent, or if I am missing it all completely, let us know.

Craig

EDIT. I would create a new topic for this thread. It will be more noticed if you do.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to create a new label field programmatically?

Post by SparkOut » Wed Sep 30, 2020 7:48 am

Is this a LiveCode project? What do you mean by installing a module, and a "fieldable entity"? Where is the 'Manage Fields' UI?

dunbarx wrote:
Tue Sep 29, 2020 10:20 pm
EDIT. I would create a new topic for this thread. It will be more noticed if you do.
I may be cynical, but I wonder whether that's desirable for a post hoping to fly under the radar? I am hesitant to accuse, but thread necromancy by a one-post user who doesn't introduce him/herself with a question that is vague and without clear reference to LiveCode does seem suspiciously like a spam placeholder.

stam
Posts: 2683
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to create a new label field programmatically?

Post by stam » Sat Oct 03, 2020 1:02 pm

Late in the game here and typing this while on a beach... but is there a template for a label field?

Still new to LC but I’m sure I saw somewhere all come trolls have templates - and it should just be a case of using that?
(I may be barking up the wrong tree here!)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to create a new label field programmatically?

Post by dunbarx » Sat Oct 03, 2020 2:51 pm

but is there a template for a label field?
All newly created controls are derived from a template. If you make a label field and set the properties of the templateField to that control, all newly created fields will be similar clones. Make a label field and name it "xxxx". Try this in a button script:

Code: Select all

on mouseUp
   set the properties of the templateField to the properties of fld "xxxx"
   create fld "xyz"
   put "New Label" into fld "xyz"
   set the top of fld "xyz" to the top of fld "xyz" + 30 --just to move it off of the rect of the "original"
end mouseUp
But note that new controls pulled from the tools palette do NOT assume the properties of the template(control). They are "stock" controls.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”