Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Scopey, scopey, scope scope.
Tue, Aug 11 2015 1:26 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Please bear with me, I've just noticed this is rather long but I wanted to give as much info as possible. The question is in the final paragraph.

I have a "main" form that loads on app start. This form has a PagePanel and a menu. Clicking the menu opens up a new tab in the panel and loads an appropriate form into it by setting its parent.

These forms need data which can only be fed to authorised users, so when the forms get loaded (into their tabs) an AJAX request is made for the data. If the server returns a 401 it pops up a modal login form.

This login form POSTs username/password to the server, and on receiving a 200 kills the login form and the user is now free to fetch the data.

Because of various cross domain scripting issues, I can't use a session cookie like I would normally, so I have built my own session management which works pretty well. On logging in I get a token returned with the 200 and I need to send this with every AJAX request. The way I've stored this token is in its own unit (UnitGlobal). I have getter & setter functions and I include this module within all forms that will request private data so they can include the token with their request.

My question - if all forms "use" this unit, how many copies of the unit exist? Is it just loaded once and this one copy stays in scope until the last one falls out of scope (garbage collection stylie)? Reason I ask is that can I be sure that the getter & setter that I call is the same one (and therefore getting & setting the same variable)? Does that make sense?
Tue, Aug 11 2015 1:28 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Just to add - it *seems* to work. Just wondering if I'm storing up an issue or whether it's just working by accident.
Tue, Aug 11 2015 5:18 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< My question - if all forms "use" this unit, how many copies of the unit exist? Is it just loaded once and this one copy stays in scope until the last one falls out of scope (garbage collection stylie)? Reason I ask is that can I be sure that the getter & setter that I call is the same one (and therefore getting & setting the same variable)? Does that make sense? >>

I think you're mixing the concept of code organization/units with variables/memory storage.

Elevate Web Builder applications behave exactly like a Windows desktop application.  If you have a unit-level variable declared in one of your units, then there is only one instance of that variable for the entire application, and its scope (visibility to other units) is determined by whether it is declared in the interface or implementation sections of the unit.

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Aug 11 2015 6:01 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Thanks Tim. I knew that, so heaven knows what I was thinking when I posted that question.

I have a habit of asking ridiculous questions when I'm deep in stuff. I sort of blurt it out as if I'm talking to someone in the same room as me (occupational hazard when you work alone from home).

Got to lay off the custard creams, and thanks for indulging me.
Image