Script - Getting/Setting Value of an Entryfield in the App by Script

How can I retrieve the value of an entryfield in my app into a script to modify this value by script and set the value of another entryfield in may app computed by this script?
brgds from BlackForest. Alex.

dim theValue as String = Textfield1.text
theValue = theValue + 3
Textfield2.text = theValue

If you want to do something different then please explain in more detail.

1 Like

What do you mean by a Script? Properties of controls on a Window can be read by Xojo code simply by referring to their name. For example an EditField can be read by a Button. Add a Pushed event to a button. In the event you can read the EditField as follows:

Event Button Pushed
   Var SomeString as String
   SomeString = EditField1.Text
   // Manipulate the value
   EditField1.Text = SomeValue
End Event

Hey Betrix,
that sounds good if the code you mention is part of the script.
I write software for label printers and I have to create customized scripts for the data-mapping in the labels layouts.
brgds. alex.

In my label printing sofware I store the values needed to print a particuar layout in a small SQLite database. That way it’s easy to add new layouts - in fact the user could do it themself if they decide to use a new label layout. Looks like this (no need for scripts at all):

Screenshot 2024-01-28 at 15.14.58

1 Like

Hey Tim,
You are right if you have the same data in the same layout in the same place.
But if you have to map data which comes from the cloud (rest-request) for each customer to an individual place within the layout a script solvels this subject for each customer inividually.
I do programming mainly in Delphi and have solved it there for windows in script technology.
Now I want to solve the same problem for macOS with Jojo.

— What do you mean by a Script? —
I mean a XojoScript (please refer to; Introduction To XojoScript — Xojo documentation)
In the documentation a XojoScript is described as a sandbox. I want to get the properties of an entryfield available in the XojoScript.
I could not find a sample or template to do so. I guess if it is possible the entryfield-property has to go with the content-property of the script into the script-code.

You cannot access items from forms etc from inside a script. You would have to use a context object and copy the control contents into properties. After the script is over you would beed Xojo code to copy context properties back into the window.

To expand on that, create a class, say ScriptSupport. Create methods or computed properties in there that access your Window and its fields, then supply a new instance of that class to your script as context. The script calls the methods/properties you created, and the class does the work.

You might even be able to supply the Window itself as context, I don’t know.

That’s exactly what I need. Delphi works the same way.
But as a Newbie in this subject I am missing some sample code how to do that.

No, the user can create as many different layouts and templates as they need. Each time they create one they can save it and it’s available for use in the future.

I meanwhile guess you are right and it’s better to work on an SQLite-Database with all Label-parameters than getting deeper into the secrets of XojoScripts.
Sorry I’m a little pampered by Delphi where you just send an object (like an entry-field) to the script and it is then fully available in the script and automatically returns the properties from the script into the app. Just in one line of code.

Why do you need a XojoScript when you can use regular Xojo code?

2 Likes