随笔 - 2146  文章 - 96 评论 - 11758 trackbacks - 253


修改 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;


posted on 2014-06-27 16:22 万一 阅读(...) 评论(...) 编辑 收藏