servercontroller.~pas
来自「Delphi深度探索,Delphi深度探索(第二版)」· ~PAS 代码 · 共 90 行
~PAS
90 行
unit ServerController;
{PUBDIST}
interface
uses
Classes,
DatamoduleUnit,
IWServerControllerBase, IWAppForm, IWBaseForm, IWApplication,
SysUtils;
type
TIWServerController = class(TIWServerControllerBase)
procedure IWServerControllerBaseNewSession(ASession: TIWApplication;
var VMainForm: TIWBaseForm);
private
public
end;
// This is a class which you can add variables to that are specific to the user. Add variables
// to this class instead of creating global variables. This object can references by using:
// UserSession
// So if a variable named UserName of type string is added, it can be referenced by using:
// UserSession.UserName
// Such variables are similar to globals in a normal application, however these variables are
// specific to each user.
//
// See the IntraWeb Manual for more details.
TUserSession = class(TComponent)
private
FId: Integer;
procedure SetId(const Value: Integer);
public
DataModule1: TdmHR;
//
constructor Create(AOwner: TComponent); override;
published
property Id:Integer read FId write SetId;
end;
// Procs
function UserSession: TUserSession;
implementation
{$R *.DFM}
uses
IWInit, CHR;
function UserSession: TUserSession;
begin
Result := TUserSession(WebApplication.Data);
end;
{ TUserSession }
constructor TUserSession.Create(AOwner: TComponent);
begin
inherited;
Datamodule1 := TdmHR.Create(AOwner);
end;
procedure TUserSession.SetId(const Value: Integer);
begin
FId := Value;
end;
procedure TIWServerController.IWServerControllerBaseNewSession(
ASession: TIWApplication; var VMainForm: TIWBaseForm);
var
UserId: string;
begin
ASession.Data := TUserSession.Create(ASession);
//读Cookie
UserID := Webapplication.Request.CookieFields.Values['UserID'];
if trim(UserId) <> '' then
begin
//写Session
UserSession.Id := StrToInt(UserId);
//显示主界面
//Move(TformMain);
TformMain.SetAsMainForm;
end;
end;
initialization
TIWServerController.SetServerControllerClass;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?