使用 IntraWeb (40) - 自定义 Session 数据

修改 UserSessionUnit 单元:


unit UserSessionUnit;

interface

uses
IWUserSessionBase, SysUtils, Classes, IWApplication; type
TIWUserSession = class(TIWUserSessionBase)
procedure IWUserSessionBaseCreate(Sender: TObject);
procedure IWUserSessionBaseDestroy(Sender: TObject);
private
FMyName: string;
FMyAge: Integer;
FMyInfos: TStrings;
public
property MyName: string read FMyName write FMyName;
property MyAge: Integer read FMyAge write FMyAge;
property MyInfos: TStrings read FMyInfos write FMyInfos;
end; implementation {$R *.dfm} procedure TIWUserSession.IWUserSessionBaseCreate(Sender: TObject);
begin
FMyInfos := TStringList.Create;
end; procedure TIWUserSession.IWUserSessionBaseDestroy(Sender: TObject);
begin
FMyInfos.Free;
end; end.

测试从 Unit1 写入数据:


uses ServerController, Unit2;

procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
begin
UserSession.MyName := 'aaa';
UserSession.MyAge := 111;
UserSession.MyInfos.Add('Var1=123');
UserSession.MyInfos.Add('Var2=456'); TIWForm2.Create(WebApplication).Show;
end;

测试从 Unit2 读取数据:


uses ServerController;

procedure TIWForm2.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
begin
IWMemo1.Lines.Add(UserSession.MyName);
IWMemo1.Lines.Add(UserSession.MyAge.ToString());
IWMemo1.Lines.Add(UserSession.MyInfos.Values['Var1']);
IWMemo1.Lines.Add(UserSession.MyInfos.Values['Var2']);
end;

上一篇:AngularJS多模块开发


下一篇:007_苹果Mac系统锁屏不待机效果设置方法介绍