每個訪問用戶都會擁有一個它的實例(WebApplication), 它除了承載 Session(會話)數據, 還要記憶着用戶的瀏覽器信息、登陸信息等等; 另外, 窗體的建立也都依附(Owner)於它, 並隨之自動釋放.
TIWApplication 所在單元及繼承鏈:
IWApplication.TIWApplication < TIWVCLComponent < TComponent < TPersistent < TObject
主要成員:
property AppUrlBase: string //測試結果: /, 在 isapi 等其它模式下會有不同, 在 gSC.AllowMultipleSessionsPerUser = True 時會有不同
property InternalUrlBase: string //測試結果: /$/
property SessionInternalUrlBase: string //測試結果: /$/
property SessionUrlBase: string //測試結果: /
property UserCacheUrlBase: string //用戶緩存基址, 測試結果: /$/MyApp/0pnlkje0r4hi7j19tzrq30eq0k2i/
property ApplicationURL: string //應用地址, 測試結果: http://127.0.0.1:3126
property CallBackProcessing: Boolean //是否正在執行回調; only read
property CallBackResponse: TIWCallBackResponse //回調響應對象
property ApplicationPath: string //程序路徑, 測試結果: C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug
property ActiveForm: TComponent //當前窗體
property ActiveFormCount: Integer //沒被銷毀的窗體數
property AppID: string //
property AuthPassword: string //用戶密碼
property AuthUser: string //用戶名
property Browser: TBrowser //瀏覽器
property Data: TObject //Session 數據
property DesignMode: Boolean //是否是在設計時
property ExecAction: string //目標地址, 默認同 FormAction
property FormAction: string //對應 Html Form 的 action 屬性
property FormCount: Integer //窗體總數
property FormWidth: Integer //瀏覽器頁面寬度
property FormHeight: Integer //瀏覽器頁面高度
property FileList: THttpFileList //上傳文件列表
property IP: string //用戶 IP
property IsCallBack: Boolean //真正處理回調
property LastAccess: TDateTime //最后一次會話請求的時間
property MasterTemplate: string //主模板地址
property ActiveMasterTemplate: string //正在使用的主模板
property SecureMode: Boolean //是否使用安全模式(SSL)
property ReferringURL: string //當前實際地址, 測試結果: http://127.0.0.1:3126/$/start
property Response: THttpReply //Response(相應) 對象
property Request: THttpRequest //Request(請求) 對象
property RunParams: TStrings //運行參數
property Terminated: Boolean //會話是否終止
property SessionTimeOut: Integer //超時時間(分鍾)
property SessionTimeStamp: TDateTime //會話開始時間
property TrackID: Cardinal //提交序列值(用戶提交的次數)
property TaggedSessionName: string //同 AppID?
property UserCacheDir: string //用戶緩存路徑
property MappedURL: string //用於獲取 ExecAction
property Permissions: TIWPermissions //XII 新增的權限控制, 只有一個 CanEditPages 屬性, 目的是可應用內置的 Html 編輯器, 我測試未成.
property CacheFiles: TStrings //緩存文件列表
property OnExecuteFormError: TExecuteFormErrorEvent //
property Forms[AIndex: Integer]: TComponent
property ActiveForms[AIndex: Integer]: TComponent
function FindFile(AName: string): THttpFile //獲取上傳的文件
procedure GoToURL(const AURL: string; const aPrependBaseUrl: Boolean) //轉到指定地址
procedure MarkAccess //更新 LastAccess 到當前時間
class function FullApplicationURL(ARequest: THttpRequest): string //返回程序的完整地址
function FindFormByClassName(const AFormClassName: string): TComponent
function FindFormByName(const AFormName: string): TComponent
procedure SendFile(const aPathname: string; const aAttachment: Boolean; aContentType: string; aFilename: string) //aPathname: 全路徑; aAttachment: True 是下載, False 在瀏覽器顯示; aContentType: 類型, 若為空則根據擴展名判斷; aFilename 重命名要下載的文件
procedure SendStream(aStream: TStream; const aAttachment: Boolean; const aContentType: string; const aFilename: string)
procedure SetActiveForm(AForm: TComponent) //一般用在 initialization 區
procedure SwitchToSecure //轉換到安全鏈接(支持 SSL 時)
procedure SwitchToNonSecure //轉換到非安全鏈接(支持 SSL 時)
procedure ShowMessage(AMsg: string; const AType: TIWShowMessageType; ATemplate: string) //AMsg: 信息; AType: smAlert, smNewWindow, smSameWindow, smSameWindowFrame; Atemplate: 模板(后兩個 Type 時), 默認 IWShowMessage.html
procedure NewWindow(const AURL: string) //Open Window, 通過下面重載可設置更多參數
procedure NewWindow(const AURL: string; const AName: string; const AWidth: Integer; const AHeight: Integer)
procedure NewWindow(const AURL: string; const AName: string; const AWidth: Integer; const AHeight: Integer; AOptions: TIWWindowOptions; const ATop: Integer; const ALeft: Integer)
procedure Terminate //終止應用
procedure Terminate(const AMsg: string) //終止並提示信息
procedure TerminateAndRedirect(const aURL: string) //終止並轉到
procedure RegisterCallBack(AName: string; ACallbackFunction: TIWCallbackFunction = procedure(aParams: TStringList) of object) //注冊函數, 會替換同名
procedure PerformCallBack(Sender: TComponent; const AName: string) //執行 RegisterCallBack 注冊的函數
function GetInternalFileURL(const AFilename: string): string //獲取內部文件鏈接, 如: WebApplication.GetInternalFileURL('js/IWBase.js')
function GetExternalFileURL(const AFilename: string): string //獲取外部文件(wwwroot 或自定義的文件夾)鏈接
procedure Lock //鎖; 以防止並發訪問
procedure Unlock //解鎖
function TryLock: Boolean //嘗試鎖(會讓其他線程等待); 成功返回 True
示例 1:
//待續...
示例 2:
//待續...
