修改 UserSessionUnit 單元:
unit UserSessionUnit; interface uses IWUserSessionBase, SysUtils, Classes, IWApplication; type TIWUserSession = class(TIWUserSessionBase) private FMyName: string; FMyAge: Integer; FMyInfos: TStrings; public constructor Create(AOwner: TComponent; ASession: TIWApplication); destructor Destroy; override; 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} { TIWUserSession } constructor TIWUserSession.Create(AOwner: TComponent; ASession: TIWApplication); begin inherited; FMyInfos := TStringList.Create; end; destructor TIWUserSession.Destroy; begin FMyInfos.Free; inherited; end; end.
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;
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;