controller.getSelectedIndex()

Does anybody know in which circumstances it can happen that forms.some_form.controller.getSelectedIndex() does not give the same result as forms.some_form.foundset.getSelectedIndex(). We have noticed that sometimes there is a difference.

In teory foundset is used to scroll the records without altering the
user inteface.

regards Armin

michel:
Does anybody know in which circumstances it can happen that forms.some_form.controller.getSelectedIndex() does not give the same result as forms.some_form.foundset.getSelectedIndex(). We have noticed that sometimes there is a difference.

thats impossible.
The data is coming from the exact same foundset, the only thing controller.getSelectedIndex() does is calling foundset.getSelectedIndex(), its just a wrapper around it.

So if that really happens then i guess that somehowe controller talks to a different foundset then when you ask the foundset through scripting…

jcompagner:
thats impossible.

That’s what I thought.

jcompagner:
So if that really happens then i guess that somehowe controller talks to a different foundset then when you ask the foundset through scripting…

And that should never happen. If I can reproduce this it can be considered a bug?

Hi Johann

Thanks for your explanation, very interesting (I myself asked what’s the difference as well). Shouldn’t you deprecate then controller.getSelectedIndex(), I would like to suggest so, because the controller.get… version is only confusing.

Best regards, Robert

we could but controller stuff is really ui, so for peoples that dont want to touch or know about the foundset but just want to change the ui
then controller.setSelectedIndex and controller.getSeletedIndex do make sense.

jcompagner:
we could but controller stuff is really ui, so for peoples that dont want to touch or know about the foundset but just want to change the ui
then controller.setSelectedIndex and controller.getSeletedIndex do make sense.

Hi Johan,

Aha now we are getting somewhere…

So you say the form.foundset.getSeletedIndex and the form.controller.getSeletedIndex can be different at the same time !?

And does this also explain the ui difference in selected index between form.controller.loadrecords and form.foundset.loadrecords ?

Regards,

lwjwillemsen:
Aha now we are getting somewhere…

So you say the form.foundset.getSeletedIndex and the form.controller.getSeletedIndex can be different at the same time !?

how did you come to that conclusion?
My previous post was:

thats impossible.
The data is coming from the exact same foundset, the only thing controller.getSelectedIndex() does is calling foundset.getSelectedIndex(), its just a wrapper around it.

lwjwillemsen:
And does this also explain the ui difference in selected index between form.controller.loadrecords and form.foundset.loadrecords ?

loadRecords through the controller can be a bit different then foundset.loadRecords but that completely depends on what you give it
For example some controller.loadRecords() can replace the current foundset, and foundset.loadRecords will always of course really change that foundset.

And i guess the selected index depends on what you give to controller… If you give a foundset to load data then the selected index is taken from the foundset that you give.

Hi Johan ,

how did you come to that conclusion?

I came to that conclusion while you said :

we could but controller stuff is really ui, so for peoples that dont want to touch or know about the foundset but just want to change the ui
then controller.setSelectedIndex and controller.getSeletedIndex do make sense.

So what do you mean then with setting the controller.selectedIndex without touching the (form)foundset ?

We have seen (hard to reproduce) difference in the controller.selectedIndex and the foundset.selectedIndex after the form.foundset.loadRecords(). When we use controller.loadRecords() the result in terms of controller.selectedIndex and the foundset.selectedIndex are always equal and correct.

Regards ,

i meant with that that you dont have to work with the foundset in you code itself.
if you just have a simple method that should set the selection in the ui
controller.setSelectedIndex is a logic choice because you want it in the UI, so you talk against the UI.

i dont know what differences you can see as i said controler selectedindex is a wrapper around founset selectedindex. you update or read in the exact same state.

dont know what you give to loadData but if that is for example a pk set then loaddata is pretty much also the same

jcompagner:
i meant with that that you dont have to work with the foundset in you code itself.
if you just have a simple method that should set the selection in the ui
controller.setSelectedIndex is a logic choice because you want it in the UI, so you talk against the UI.

i dont know what differences you can see as i said controler selectedindex is a wrapper around founset selectedindex. you update or read in the exact same state.

dont know what you give to loadData but if that is for example a pk set then loaddata is pretty much also the same

Hi Johan,

I give the loadRecords() a (form) foundset as parameter…

I think the wrapper is not always fired in case of form.foundset.loadrecords(other foundset)

Regards,

as i said before

controller.loadRecord(foundset)
and
foundset.loadRecords(foundset)

are different…

the first replaces the current foundset completely, you “loose” the existing one.

the second copies the state of the given foundset into the current one, so you keep the existing one.

jcompagner:
as i said before

controller.loadRecord(foundset)
and
foundset.loadRecords(foundset)

are different…

the first replaces the current foundset completely, you “loose” the existing one.

the second copies the state of the given foundset into the current one, so you keep the existing one.

Johan,

Could you state both cases in terms of selectedIndex after the loadRecords ?

So,

controller.selectedIndex value and foundset.selelectedIndex value after controller.loadrecords(foundset)

and

controller.selectedIndex value and foundset.selelectedIndex value after foundset.loadrecords(foundset)

As I said earlier we noticed sometimes a difference between the controller.selectedIndex value and the foundset.selelectedIndex value after the foundset.loadrecords(foundset)…

both should have the selected index of the foundset you give as the argument.

jcompagner:
the second copies the state of the given foundset into the current one, so you keep the existing one.

this confuses me also… :?

keep the existing one? where is it kept/stored?

how is that confusing?

if you have this:
var previousfoundset = forms.x.foundset;

and then you do this:
forms.x.controller.loadData(otherFoundset)

then previousfoundset is not forms.x.foundset anymore
Its different, you replaced it with the otherFoundset
previousfoundset != forms.x.foundset
but
otherFoundset == forms.x.foundset (very likely this also doesnt have to be the case if that form says it wants always to have a seperate foundset…)

But if you do this:
forms.x.foundset.loadData(otherFoundset)

then previousFoundset is still the same as forms.x.foundset

Because the state of the otherFoundset is copied into the current foundset, Keeping that foundset

so
previousfoundset == forms.x.foundset
and
otherFoundset != forms.x.foundset

oke thanks for explaining this, I understand now…

jcompagner:
both should have the selected index of the foundset you give as the argument.

Johan,

As I said : this is unfortunately not always the case . :?
We have a kind of selectedindex-check in our framework when toggling from table to detailview (different forms on the same table) and vice versa to keep the focus on the same record.
We noticed with foundset.selectedIndex the test was unreliable.
Changed to controller.selectedIndex the test works ok every time over and over…

i have no idea then
controller.setSelectedIndex is just some extra indirection to the same call on the foundset
If there is one that could maybe fail more often, then that would be controller.setSelectedIndex because that one goes over more steps to get to the same thing.

jcompagner:
how is that confusing?

if you have this:
var previousfoundset = forms.x.foundset;

and then you do this:
forms.x.controller.loadData(otherFoundset)

then previousfoundset is not forms.x.foundset anymore
Its different, you replaced it with the otherFoundset
previousfoundset != forms.x.foundset
but
otherFoundset == forms.x.foundset (very likely this also doesnt have to be the case if that form says it wants always to have a seperate foundset…)

But if you do this:
forms.x.foundset.loadData(otherFoundset)

then previousFoundset is still the same as forms.x.foundset

Because the state of the otherFoundset is copied into the current foundset, Keeping that foundset

so
previousfoundset == forms.x.foundset
and
otherFoundset != forms.x.foundset

This should be documented somewhere if it isn’t already. The difference between controller.loadRecords and foundset.loadRecods has been a question we have had since using Servoy. Thanks for this explanation! :)