FoxInCloud
How to tell when a form's init() is run per user?
Gravatar is a globally recognized avatar based on your email address. How to tell when a form's init() is run per user?
  Paul
  All
  Dec 13, 2018 @ 03:27pm

Hi,

thisform.wlInitFirst tells us if this is the first time the form has ever been initialised.
How can I know if this is first time the form's Init() has been run when a particular user "opens" the form and not when subsequent server requests by the user are made to it?

To give a contrived example :
I want to position the form at the bottom of the screen/page when Bob "opens" it, but not every time he does something that triggers a server request (and another call to form.Init() ). Same thing when Alice "opens" the form in her browser.

Thanks
Paul

Gravatar is a globally recognized avatar based on your email address. re: How to tell when a form's init() is run per user?
  FoxInCloud Support - Thierry N.
  Paul
  Dec 14, 2018 @ 12:38am

form.Init() executes:

  • once when form gets first instantiated (.wlInitFirst), WITHOUT A USER CONTEXT, and without parameters >> from this state FoxInCloud generates HTML/CSS/JS and stores the form state in Temp\form_Init.dbf; at this stage, to have the initial HTML without data, it's better to have views and cursors nodata and tables on eof() if they enter in some .controlSource
  • each time a user executes [.]wForm*(), with the related user context and parameters, then you requery the views and cursors, and/or set recno() on aliases.

For your contrived example:

  • supported in classic mode only; in Bootstrap responsive mode, Bootstrap positions the 'dialogs'
  • FoxInCloud natively supports form.Move() and form.resize() (based on .Anchor), stores position and dimension across user's sessions (recycles when user opens a new session), restores form's position and dimensions next time user opens it.

demo: http://foxincloud.com/tutotest/, open form as child form using the buttons and move it around, and/or resize, close it, re-open it; video: https://youtu.be/TyDRFm2nKPs

Gravatar is a globally recognized avatar based on your email address. re: How to tell when a form's init() is run per user?
  Paul
  FoxInCloud Support - Thierry N.
  Dec 16, 2018 @ 08:27pm

Thanks.
My example was really about how to execute a piece of code the first time a user "opens" or navigates to a form and not every time the user makes a request to the form just because a Valid() fired or a button is clicked etc.
In other words, like the Init() would work in lan mode - but in web mode 😉

I suppose I could code my own flag in a form, that is set to true when the Init() is called in web mode and !this.wlInitFirst, but I'm wondering if FiC already has something like this.

Paul

Gravatar is a globally recognized avatar based on your email address. re: How to tell when a form's init() is run per user?
  FoxInCloud Support - Thierry N.
  Paul
  Dec 17, 2018 @ 04:00am

form.Init() runs once after .wForm*(), NOT before other user requests.

So, except when .wlInitFirst, form.Init() runs the same in desktop and Web modes.

procedure form.Init
…
if thisForm.wlInitFirst
  && just instantiated, no user context
  return
endif
…
&& the code after this point executes:
&& - in desktop mode
&& - in web mode for each user using this form

if thisForm.wlWeb
  && running in Web mode
endif

if thisForm.wlLAN
  && running in desktop mode
endif
Gravatar is a globally recognized avatar based on your email address. re: How to tell when a form's init() is run per user?
  Paul
  FoxInCloud Support - Thierry N.
  Dec 17, 2018 @ 12:09pm

Ahh, that makes it easy then.

Thanks.
Paul

© 1996-2024