field contents

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

Post Reply
comodo51
Posts: 10
Joined: Thu May 05, 2011 11:08 am

field contents

Post by comodo51 » Thu May 05, 2011 11:35 am

Hi all,
I am a beginner with LC.
When I run my app in Livecode I may change the field contents in every manner to test my app.
When I save the app as standalone and run the .exe the app display the last content of the field that I have changed during "debugging".
Like in VB I need to set a default value for the contents of the field and have "that" value in my .exe.

Thanks for your help

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

Re: field contents

Post by SparkOut » Thu May 05, 2011 12:01 pm

You can do

Code: Select all

on openStack
  put <your default value> into field "<yourfieldname>"
end openStack
If the field is not on the first card of the stack then you can

Code: Select all

on openStack
  put <your default value> into field "<yourfieldname>" of card "<yourcardname>"
end openStack
as necessary. This could equally work on preOpenStack. Depending on how many fields for which you need to set a default value you could make this very generic using custom properties and a loop through all the controls on the card or stack to get the default value from a custom property of each field and put it into the field for display.

comodo51
Posts: 10
Joined: Thu May 05, 2011 11:08 am

Re: field contents

Post by comodo51 » Thu May 05, 2011 12:12 pm

Thanks,
I hope not but this is a terrific way to set default value.
In order to see which are the default I have to read the scripts.
Not only, I have to set in every stack for every card the loop through al the controls!

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: field contents

Post by Klaus » Thu May 05, 2011 12:37 pm

Hi comodo51,
comodo51 wrote:Thanks,
I hope not but this is a terrific way to set default value.
Get used to it! You are the developer and you are responsible for this stuff now :D
comodo51 wrote:In order to see which are the default I have to read the scripts.
No, you can use a custom property here!
Check this posting of mine, wehre I give some infos about custom properties:
http://forums.runrev.com/phpBB2/viewtop ... 125#p34125
comodo51 wrote:Not only, I have to set in every stack for every card the loop through al the controls!
Yes, and what exactly is the problem? 8)

You can do this:
Assign a custom property e.g. "cInitialValue" to your fields, that need to display a certain string.
Inspector for that field: Custom Properties
But even that can be done via script.

Then you can loop through all cards of your stack and display this value/string in the fields:

Code: Select all

...
## Maybe "on preopenstack"
repeat with i = 1 to the num of cds
  repeat with k = 1 to the num of fields of cd i
    put the cInitialValue of fld k of cd i into tValue

    ## Now do whatever you need to do here:
    if tValue <> empty then
      put tValue into fld k of cd i
   end if
 end repeat
end repeat
...
Eight lines, I am sure you can live with this :D


Best

Klaus

comodo51
Posts: 10
Joined: Thu May 05, 2011 11:08 am

Re: field contents

Post by comodo51 » Thu May 05, 2011 2:11 pm

Thanks Klaus,
it's very kind of you.

But , excuse my inexperience, I think that almost any programmer need to test his app, and tests need the insertion of text, combo, check, move the main stack and so on.
Hence, all the developers have to set customproperties for setting the default value of each value that can be changed during the test for each object of the app.

Don't you think that it would be better directly manage this situation in LiveCode instead of force every developers to write "only" eight lines (but are much more) for every object of every app?

Regards

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: field contents

Post by Klaus » Thu May 05, 2011 2:32 pm

comodo51 wrote:But , excuse my inexperience, I think that almost any programmer need to test his app, and tests need the insertion of text, combo, check, move the main stack and so on.Hence, all the developers have to set customproperties for setting the default value of each value that can be changed during the test for each object of the app.
Depends on their needs, but in general yes.
comodo51 wrote:Don't you think that it would be better directly manage this situation in LiveCode instead of force every developers to write "only" eight lines (but are much more) for every object of every app?
No, I don't think so :D
What would you propose?


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: field contents

Post by dunbarx » Thu May 05, 2011 3:34 pm

Hi.

If I understand correctly, there is a default value for each field that must be restored for each new session. These fields may have their values changed within a session.

You are asking for a native field property that causes the field to revert to some fixed value when the app is closed.

I understand what you want, but Klaus is right in that this is a small task that is properly managed by the developer.

What he suggests is sort of what you want: put the default data into a custom property and set it upon openstack (or closeStack). The logic of this is clear and robust. It only has to be written once, and does not depend on whether or not you change the number of fields or their locations. You do understand this, right? I first thought that this might be what you were up against, that the number of fields or their location on different cards could change, and might be hard to manange.

Craig Newman

comodo51
Posts: 10
Joined: Thu May 05, 2011 11:08 am

Re: field contents

Post by comodo51 » Fri May 06, 2011 5:08 pm

Hi Craig,

I see you understand the real problem.
It regards not only the field text content, but, in general, involves many properties of the objects of the cards that, during the debugging of the app, may change programmatically their values.

In my app, for example, I can set invisible some fields under certain conditions; if I exit from the debugging mode the visible property remains set to false.
To manage this case I have to set "via script" the default value of visible property, and so on.

I wonder if it might be considered the possibility to distinguish between properties setted via "property inspector" and properties setted via script or message box.
In this way, with a check box, I could "lock" the properties setted via "property Inspector" so that when I restart the app (restart from the beginning) I restart always from the same value.

I think this feature would be much appreciated, not only by beginners; indeed, this feature would be very useful to professional programmers who develop complex or large applications.

Thanks

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

Re: field contents

Post by SparkOut » Fri May 06, 2011 6:45 pm

Hi Commodo

You must understand that this is something that I don't want as unnecessary clutter and not appropriate for all my work. However, you as the developer are in control of what you want to do. As you get used to programming with Livecode you will see that there are many scripts and "toolbox" techniques that you would like to reuse over many projects and begin to build yourself a library of scripts with functions and handlers that you reuse time and again. Sometimes it will be worth including those toolbox items in a library stack that you include as a substack of each of your projects. Perhaps you would like to add these handlers to yours:

Code: Select all

on saveCurrentState
   repeat with iCard = 1 to the number of cards of this stack
      --you can expand to check for the openStacks or stacksInUse as you see fit
      repeat with iControl = 1 to the number of controls of card iCard of this stack
         set the uProps of control iControl to the properties of control iControl
      end repeat
   end repeat
end saveCurrentState
  
on setDefaultState
   repeat with iCard = 1 to the number of cards of this stack
      --you can expand to check for the openStacks or stacksInUse as you see fit
      repeat with iControl = 1 to the number of controls of card iCard of this stack
         set the properties of control iControl to the uProps of control iControl
      end repeat
   end repeat
end setDefaultState
"the properties" of any object are many (not *all*) of the main property features of the object, including visibility, the rect, the text of a field, etc, etc.
So if you want to take a snapshot of the "default" state, then call the above handler "saveCurrentState" at an appropriate moment when you have all fields and settings as you require. In a dynamic situation this may be on saveStackRequest, for instance. Otherwise just do it when you know things are set the way you want them.
Then at an appropriate moment, (for instance on openStack - or, for that matter on saveStackRequest, depending on what situation you have) you can call the handler setDefaultState.
These handlers loop through every control on every card of the stack in question (you can expand it to check for other stacks in use or substacks etc as you require) saving/restoring the current state of each control into/from custom properties of the said control.
I hope you'll agree, it's not a really difficult task to achieve what you want without using built-ins, and that you'll also see why such an overhead is not something that would always be desirable.
Of course we all have our own wishlists! (I'd like various things, only one of which is for pre 1970 dates to be recognised by the built in date functions, on Windows)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: field contents

Post by dunbarx » Fri May 06, 2011 11:51 pm

As sparkout has said, this is not only appropriate, but fun and robust. One thing you might consider, when you set "the properties", this is a default set, all of which are NATIVE properties. You want to set CUSTOM properties, so you have to write that yourself. Create a button and a field. Name the field "F1".

In fld "F1", create a custom property called "defaultText" and set it to: "Hello" (don't put the quotes)

In the button script write:

Code: Select all

on mouseUp
   set the text of fld "F1" to the defaultText of fld "F1"
end mouseUp
Now if you type anything into that field, and then press the button, the word "hello" will appear. If you place this hander in an openStack script, it will reload that text each time the stack is opened.

Go a step further, and add other custom properties.

Go a step further, and see what you make of this:

Add a custom property to field "F1" called "defaultProps", and set it to:

visible true
loc "100,100"
text hello

In the button place this handler:

Code: Select all

on mouseUp
  put the defaultProps of fld "f1" into temp
   repeat with y = 1 to the number of lines of temp
      do "set the" && word 1 of line y of temp && "of fld f1" && "to" && word 2 of line y of temp
   end repeat
end mouseUp
Now move the field somewhere, put in some random text, and hide the field. Press the button. I hope you get the idea.

What on earth is the story with that "do" thing? Try rewriting it with a line for each of those properties.

Craig Newman

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

Re: field contents

Post by SparkOut » Sat May 07, 2011 1:06 am

If you use the "saveCurrentState" handler I showed above, it will store all the current (native) properties for each of the controls in a custom property of the relevant control. Whenever "the properties" of an object are checked, it shows the current set of those properties, which do include the text, htmlText, visible, rect, etc. so field contents and size/position will be retained, for sure. So it isn't necessary actually even to create default values custom properties to be used individually. Just adjust the stack to be how you want, with fields empty or containing default values, etc, then store the "snapshot" of that set of controls with the "saveCurrentState" handler. Check the dictionary entry for "properties" and you can see some of the restrictions on what will not be possible to be saved in this manner.
Save the stack. Now the stack has a record of all the "default" properties of all the controls stored relevant for each control.
Then when you want to restore everything to the default (snapshot stored) state, use the "setDefaultState" handler to copy the custom properties back to being the "live" properties for each control. Of course, this way, every single control has extra, largely unnecessary data stored in a custom property.
Craig's way at least reduces all the unnecessary repetition of property storage for each control.

comodo51
Posts: 10
Joined: Thu May 05, 2011 11:08 am

Re: field contents

Post by comodo51 » Sat May 07, 2011 1:27 pm

Hi all.

I decided to use LC as my new development environment.
And before you start doing real, it is necessary to define all the utilities that serve to develop, fast and easy, all future applications.
Sparkout, I fully understand your tip and I'll use it.

Thanks.

Post Reply