Storage For Delphi ApplicationsLast Updated: 10/14/2005 | |
| Sections above here: Home » Development » State Management | |
|
Sections below here: Topics in this section: |
Safe Storage in IntraWeb for DelphiForm / Datamodule MembersThis section refers to IntraWeb for Delphi only: since IntraWeb forms and datamodules are persistent just like in a normal Delphi application you can store information as member variables and properties. Such members should be used when the form itself needs to store data about its instance or to receive input from another form. User SessionThe user session (covered more in detail in the Session Management section of
this manual) contains a .Data property that can hold a reference to an object.
When you need to store user specific information you can store it in the .Data
property of the session. Data accepts a TObject instance and will destroy the
TObject automatically when the session is destroyed. The easiest way is to
create an object and add the fields that you wish, and then create your object
and store it in the session's Data property when the session is created. The
Phonetics demo shows an extended example of this. unit ServerController;
unit ServerController;
interface
uses
SysUtils, Classes, IWServerControllerBase,
IWApplication, IWAppForm;
type
TIWServerController = class(TIWServerControllerBase)
procedure IWServerControllerBaseNewSession(ASession: TIWApplication;
var VMainForm: TIWAppForm);
private
public
end;
TUserSession = class
public
end;
// Procs
function UserSession: TUserSession;
implementation
{$R *.dfm}
uses
IWInit;
function UserSession: TUserSession;
begin
Result := TUserSession(RWebApplication.Data);
end;
procedure TIWServerController.IWServerControllerBaseNewSession(
ASession: TIWApplication; var VMainForm: TIWAppForm);
begin
ASession.Data := TUserSession.Create;
end;
end.
TUserSession is an empty session object that you can add members, properties
and methods to. The code to create the TUserSession for each session is also
created in the OnNewSession Event. TUserSession = class
public
Username: string;
Password: string;
end;
You could access these properties elsewhere in your code simply as shown
here: UserSession.Username := 'Joe'; LPassword := UserSession.Password; If you do not need a user session you may choose to eliminate it from the
code. It is not necessary and is part of the default template simply as a
convenience. |
(C) 2002-2009 - Atozed Software Ltd. | |