This is what I am thinking. A global type of function that would be able to determine where to go based on what was clicked. An onAction method would look like this.
switch ()
{
case lastClicked(button, name == "My Button") :
go somewhere;
case lastClicked(button, name == "Your Button") :
go somewhere else;
case lastClicked(button, name == "Their Button") :
go crazy;
default :
say "You're lost";
}
syntax would be the follwing
lastClicked(objectType, property 1 [property n])
The cool thing about this type of function would not only be making a universal type of naviation, as above, but it would also allow you to watch for coordinates within images. For example.
if (lastClicked(image, location == 0,0,10,10){
say "You clicked on my town"
}
When the image was a map and you clicked in the upper corner within 10 pixels of the top left edge.
Can this be done currently? Sound like a great function?
If we were to have the “this” property or a “me” or a “self” (realbasic equivalent), it would be a whole lot easier to generalise your code, like in if (me.name == “somebtn”)
do this
And I think it would be real easy to implement. We need a notion of the “currentelement” (like the currentcontroller), and the elements name property would need to be public or a getElementName method would need to exist.
your suggested me or self reference was what I was thinking of too… Although this would make much more sense, in my humble opinion, if we would have methods and events proprietary to the control (like in REALbasic). I guess…
Yes Servoy is aware of the JS objects, there are currently only no back references between them… we could provide the initiating element as arguments[0] to your method and provide a getName() method on all elements.
so then you could do in your method:
var elementName = arguments[0].getName();
to get the current element name starting this method.
whould that help?
x can be DataField[NameofField:DataProvider],
or ScriptButton[Name]
or ???
however I’m don’t seem to be able to retrieve the items inside the ( without using regex) hence my question for a getName().
elements seems to be an alfabeticaly ordered array(Please correct me if I’m wrong). I would like to see it ordered (optionally ?) by TabSeq and the TabSeq property retrievable by a method (getTabSeq()) or as a Public property.
This would “connect” the programming logic with the user interface logic and introduce concepts as the “next” and “previous” element ( as seen by the user of the form)
since we submitted in the exact same minute, would you please also react on my point 2 (pref with the words: great idea we are implementing this as we speak, or something along those lines)
I think all that would give us the possibility to ‘know’ what object/element started something would help us. Although, it could be important but it doesn’t keep me from doing what needs to be done! Yet
We have added application.getMethodTriggerElementName() which returns the name of the element being the source. (which is easier than passing the element as argument)
With the name you can lookup properties like:
var elementText = elements[application.getMethodTriggerElementName()].text;
var bgcolor = elements[application.getMethodTriggerElementName()].bgcolor;
etc.
tip:
If you want to start using elementnames on a global level you might need the form name as well (formName + elementName makes a unique String)
global script name = getElementName
var elementName = application.getMethodTriggerElementName()
var formName = arguments[0]
…
button script somewhere in a form
globals.getElementName(currentcontroller.getName());
explanation:
If you click the buttonscript, the global script will be triggered AND it will receive the argument “currentcontroller.getName()” which is the form where the button was clicked.
Coming back to an old topic, is it a) possible, b) useful, to allow an optional argument to an OnAction method in the form editor. In this way, the method called by the click can behave differently, depending on the argument(s) passed. Saves having to name each button for the GetTrigger… function.
Nope, not possible other than (maybe) using the text attribute of the button and changing the text after an action. Like, for example, set the text of a button to ‘open’ and change it to ‘close’ when the button was clicked. As a result you can do different things when you read the text.
useful and possible.
I’ve discussed this with Jan Blok some time ago.
The idea is to have a property on a button that you can fill with arguments.
These arguments are automatically sent onClick, to the (global) script that’s attached to the button.
Saves you declaring a local script that sends arguments to the global script
You don’t have to “mis use” element names in order to get information across the system.
Will see if we can push this up the prio list a bit