程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 使用 IntraWeb (40)

使用 IntraWeb (40)

編輯:Delphi


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


測試從 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;


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved