Posts: 92
Threads: 33
Joined: May 2018
Reputation:
0
Location: Sweden
Hi,
I'm using this function with great success.
But I need to reference a variable in the UserSession. How do I do that?
Posts: 2,261
Threads: 196
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
I suppose that within your code you have access to your WebApplication instance, is that correct?
The property Data of the WebApplication contains a reference to your UserSession object:
UserSession := TIWUserSession(WebApplication.Data);
However, the typecast will require you to link the unit with this code to the UserSessionUnit where TIWUserSession is declared.
Another alternative is to use the UserSessionBase (the parent class of your UserSession) Clipboard object to temporarily store some values that are needed elsewhere. Something like:
uses
IWUserSessionBase;
UserSession := TIWUserSessionBase(WebApplication.Data);
// Store the value there
UserSession.Put("LoggedUser", "Mikael Nilsson");
// Store the value there
UserName := UserSession.Get("LoggedUser");
Note that in this example I don't need to link with the UserSessionUnit, only with the IWUserSessionBase unit which is part of the IW not your application. You can have a more generic approach using this.
Posts: 2,261
Threads: 196
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
So use the first line that I wrote in my response:
UserSession := TIWUserSession(WebApplication.Data);
Now you have your UserSession and is able to call it's methods
Posts: 2,261
Threads: 196
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
The exception handler executes in case any exception is raised, including the ones that occur outside the scope of a session. In this case, no IWApplication instance will exist. In some other cases it will...
That's why our TIWExceptionLogger was designed to save a plain text file on the hard disk, because the disk is always available.