使用 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;


使用 IntraWeb (40) - 自定义 Session 数据,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。