locked
Parameters use in init methods RRS feed

  • Question

  • Hi all,

    I use vfp9 sp2 and win xp.

    When I call a form with parameters and want to use the parameters in objects' init methods before the form.init method is called, what do I do?

    It is my understanding that all objects' init methods are called before form.init.

    My work-around has been to create a form method, called, say, grid1init. I call it from form.init and put all the grid1.init code in it.

    There must be a better way! :)

    Regards,

    Jan Nordgreen
    Wednesday, July 11, 2012 10:34 PM

Answers

  • There is a reason, why form init is coming last. Otherwise it wouldn't be possible for form.init code to alter controls, set controlsources etc., so the intention is to setup the controls from the form init. The same goes for data access. If form parameters are filter parameters, you better use views with nodata, then set view parameters in form init and requery.

    If you want to make use of control init parameters there is no chance by visually adding them to a form, instnciating controls by .AddObject() would allow you to make use of parameters.

    The prerequisite of a cursor/alis name present to pass in values would be one way, even better would be the init code would by default get it's initialisation values from a biz object it instanciates and queries neccessary meta data for it's own setup.

    Another striaght forward solution to replace parameters would be defining new properties you set at design time, as long as you can do that. Or set them to expressions you evaluate at runtime.

    Bye, Olaf.

    Friday, July 13, 2012 3:19 PM

All replies

  • No, there is no other way to pass parameters into form objects.

    (You could save some values to global variables BUT this is really not recommended approach in OO world because it breaks basic OO rules.)

    Wednesday, July 11, 2012 11:00 PM
  • Hi Jan,

    you could create a 'parameter' cursor. As long as the called form has access to that cursor (and datasession it is stored in), your objects could make use of its content.


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011

    Thursday, July 12, 2012 12:37 PM
    Answerer
  • There is a reason, why form init is coming last. Otherwise it wouldn't be possible for form.init code to alter controls, set controlsources etc., so the intention is to setup the controls from the form init. The same goes for data access. If form parameters are filter parameters, you better use views with nodata, then set view parameters in form init and requery.

    If you want to make use of control init parameters there is no chance by visually adding them to a form, instnciating controls by .AddObject() would allow you to make use of parameters.

    The prerequisite of a cursor/alis name present to pass in values would be one way, even better would be the init code would by default get it's initialisation values from a biz object it instanciates and queries neccessary meta data for it's own setup.

    Another striaght forward solution to replace parameters would be defining new properties you set at design time, as long as you can do that. Or set them to expressions you evaluate at runtime.

    Bye, Olaf.

    Friday, July 13, 2012 3:19 PM