onLoad: when executed?

Hi

In our application we have a form called XXXConfiguration. This form contains information about the selected language, some special value lists and some other configuration data. It offers some getter methods (e.g. getLanguage) to other forms. But it has no GUI.

I did hook on load event to call the method XXXConfiguration>onLoad(). In this method I initialize the form XXXConfiguration and set the variables. I thought that this on load method will be called whenever an other form calls forms. XXXConfiguration.getLanguage(). But I’m no longer sure. Since sometimes I get an error saying that a variable is not defined.

Could please anyone tell me, when XXXConfiguration>onLoad will be called? And does it interfere with an other onLoad method of an other form? Is an order of these onLoad methods guaranteed? What else could be the problem?

Thanks in advance for any help
Birgit Rieder

In our application we have a form called XXXConfiguration. This form contains information about the selected language, some special value lists and some other configuration data. It offers some getter methods (e.g. getLanguage) to other forms. But it has no GUI.

I think I misinterpret what you say here but a form without GUI? Is that possible?

I did hook on load event to call the method XXXConfiguration>onLoad(). In this method I initialize the form XXXConfiguration and set the variables. I thought that this on load method will be called whenever an other form calls forms. XXXConfiguration.getLanguage(). But I’m no longer sure. Since sometimes I get an error saying that a variable is not defined.

On load is called when the form is loaded for the first time and not every time it is referred/called to.

Could please anyone tell me, when XXXConfiguration>onLoad will be called?

See the above

And does it interfere with an other onLoad method of an other form?

Not that I am aware of.

Is an order of these onLoad methods guaranteed?

I can not answer this but I guess so.

What else could be the problem?

Well, on load is all about setting/creating the form before any data is available. So, when you refer to data that should be on the form you have an issue. I only use on load to create certain security settings etc.

Hi Marcel Trapman

Thanks for your answer.

Why should a form without GUI not be possible. How do you solve the configuration I described? Don’t you ever have a group of methods solving a problem like user defined configuration, special value lists, a registry and so on. They all offer some helpful methods but no GUI.

Yes, true, onLoad is only called once. But when? When is the form (without GUI) loaded? I made some debugging (wrote to output) and found, whenever I call a method (the first time) of that form. But sometimes I get an error telling the variables are not yet defined. Why sometimes?

By the way: when is the on open method of the solution executed?

Regards
Birgit Rieder

Why should a form without GUI not be possible. How do you solve the configuration I described? Don’t you ever have a group of methods solving a problem like user defined configuration, special value lists, a registry and so on. They all offer some helpful methods but no GUI.

Don’t feel offended! I asked you a question, was not playing smartass or something of the likes.

Yes, true, onLoad is only called once. But when? When is the form (without GUI) loaded?

When you do a call to a form for the first time it is ‘created’ or loaded and as such the onload is called at that same time.

I made some debugging (wrote to output) and found, whenever I call a method (the first time) of that form. But sometimes I get an error telling the variables are not yet defined. Why sometimes?

No idea, this is too generic to answer.

By the way: when is the on open method of the solution executed?

When you say ‘when’ I would say when you open the solution but I guess that is not what you are looking for. You probably want to know in what sequence as opposed to other ‘activities’ while starting a solution. When that is really important you may want to do a test. Knowing you however you already did that :) So I am overasked here and I think a Servoyan should answer this (as with the above probably).

Thank you for not answering “on open is called when the solution is opened.” :D

And thanks again for the answers, Marcel Trapman.

Back to on load: Since I only sometimes get the error I guess it is a timing problem. Another guess: Since onLoad is executed whenever I call a method the first time on that form, is it possible, that onLoad is executed in an other thread? So that the calling method will be executed “in parallel”?And accessing a variable from the calling method will only succeed if onLoad was fast enough to finish initialization before the access is done? The calling method may also be a onLoad method, by the way.

A lot of guessing. Is there anyone who knows?

Thanks
Birgit

Birgit, I assume you picked up ‘before any data is available’.
So, when you talk about calling a method, that method should not refer to data that is in the table that the form is based on…

I did not understand exactly what you mean. Let me come up with my example in more detail. Form A is based on table persons, form B on table roles:

formA>onLoad
  calls formB>getNaturalRoles; //gets a list of roles ('students', 'teachers', ...)
  //by calling getNaturalRoles, the onLoad method of formB 
  //will be executed:

    formB>onLoad
      "SELECT ... FROM roles WHERE..."; //stores role names in a variable

  //back to on load of form A: getNaturalRoles returned a list of strings.
  ..setValueListItems .... //now I set the value list items of a combo box
  //of form A to the items returned by getNaturalRoles.

Do you see any place where I’m “picking up” data before I should? What could go wrong here? Will there anything run parallel (e.g. getNaturalRoles and formB>onLoad)

Thanks
Birgit

Birgit, if I understand right you want to use a form without showing it to the user.
If this is correct try to initialize the form like this in your onOpen method:

forms.formB

This should load you form into memory and execute your onLoad method.

Thank you very much for your answer. I’ll try, if it solves the problem.

If this would solve the problem, then the downside would be, that, whenever I call such a method (I have 17 now), I have to call forms.formX first. Or I implement a method like call() with arguments formname and method and optional arguments. It first calls the form like you suggested to trigger onLoad if neccessary and then executes the passed method (with or without arguments). Not a really good solution either.

If your suggestion solves the problem, what was the problem then? Is there no save way to do some initializations?

Regards
Birgit Rieder

I have a related question.

If have found that if on startup a solution immediately looks at forms.myForm.foundset.getSize() before doing anything else with myForm or its foundset, it returns zero. It would seem the foundset isn’t established until I do one of the following:

  • show the form or some other form based on the same foundset
  • explicitly load records into its foundset using loadRecords()

Is this the expected behavior or should I be looking for something I’m doing wrong?

Thanks.

I would say this is expected behaviour. If it wasn’t that way, Servoy had to fire many queries to populate all kinds of foundsets that might not even be needed throughout the session.

Servoy could decide to establish the form’s default foundset upon first encountering any of the foundset operations such as getSize(), and still avoid needless loading of foundsets.