Loop count reversed

Questions, tips and tricks and techniques for scripting in Servoy

Loop count reversed

Postby Gordon » Wed Oct 21, 2009 2:19 pm

Hi All

I have been trying to use the Solution Model to insert content into an existing form. ie dependant on the users response I want to extend a form or not as the case may be. This seemed a simple case of slotting in a set of questions to the base form and moving the remaining elements down the page - not hard BUT Servoy served up a strange problem before I got to the Sol Mod:

I created a simple form with 7 fields and 7 labels named a/aa, b/bb etc. I want to move rows 3 - 7 down by 100px - I did the following:

for(i=1;i<=10;i++)
{
application.output(i + elements[i-1].getName())
var x = elements[i-1].getLocationX();
var y = elements[i-1].getLocationY();
elements[i-1].setLocation(x,(y+100));
}

IF you run this in the developer smart client you sure enough move elements 3,4,5,6 and 7 down 100 px IF you do exactly the same in the web client you move 1,2,3,4, and 5 down. When you output the name of the element being processed the smart client starts at the end and works back and the web client starts at the beginning and works forward.

Webclient output:
1a
2aa
3b
4bb
5c
6cc
7d
8dd
9e
10ee

Smart client output
1gg
2g
3ff
4f
5ee
6e
7dd
8d
9cc
10c

If anyone can see what I have missed I would be very interested. Obviously I can get around the problem by detecting the app type BUT in the spirit of Servoy fits all this is a bit of an issue !!

Best wishes
Gordon
Gordon McLean
Click Digital Media Ltd
SAN Developer
www.clickdigital.com
User avatar
Gordon
 
Posts: 265
Joined: Thu Mar 17, 2005 8:05 pm
Location: UK

Re: Loop count reversed

Postby jcompagner » Fri Nov 20, 2009 4:50 pm

we do not guarantee any order,
for example tableview in the web will be completely different again.

You seem to assume that the order is based on the location of that component on the screen.
that doesnt have to be the case at all, What if you move the element your self like you do?
then you expect that if you moved element[1] below element[3] that the next time you ask for it element[1] will be element[3] ??

The best way to do this is first sort your elements based on there current location and then do your stuff based on the index that you create yourself.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Loop count reversed

Postby Gordon » Fri Nov 20, 2009 5:00 pm

jcompagner wrote:we do not guarantee any order,
for example tableview in the web will be completely different again.

You seem to assume that the order is based on the location of that component on the screen.
that doesnt have to be the case at all, What if you move the element your self like you do?
then you expect that if you moved element[1] below element[3] that the next time you ask for it element[1] will be element[3] ??

The best way to do this is first sort your elements based on there current location and then do your stuff based on the index that you create yourself.


Thanks for the reply, I will have a go at this approach.

best
Gordon
Gordon McLean
Click Digital Media Ltd
SAN Developer
www.clickdigital.com
User avatar
Gordon
 
Posts: 265
Joined: Thu Mar 17, 2005 8:05 pm
Location: UK


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests