📄 uistatenav.pas
字号:
{
组件:界面历史导航组件
作者:程龙华
创建日期:2005-10-9
}
unit UIStateNav;
interface
uses
SysUtils, Classes,Controls;
type
TUIStateData=record
NavigationID:integer;
DetailID:integer;
TagString:string;
Tag:integer;
end;
TPUIStateData=^ TUIStateData ;
TUIStateNotifyEvent=procedure (Sender:TObject;aUIState:TPUIStateData) of object;
TUIStateNav = class(TComponent)
private
FUIToNav: TWincontrol;
function GetHistory(index: integer): TUIStateData;
function getHistoryCount: integer;
protected
{ Private declarations }
FNavigating:boolean;
FHistory:TList;
FIndex:integer;
FUI:TWincontrol;
FCapacity:integer;
FActive:boolean;
FOnSaveUIState:TUIStateNotifyEvent;
FOnRetrieveUIState:TUIStateNotifyEvent;
{ Protected declarations }
public
{ Public declarations }
property HistoryCount:integer read getHistoryCount;
property History[index:integer]:TUIStateData read GetHistory;
procedure UpdateUIStateByData(aUIStateData:TPUIStateData);
procedure RecordUIState;
procedure UpdateUIState;
property Index:integer read FIndex write FIndex;
procedure Forward;
procedure Backward;
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property UIToNav:TWincontrol read FUIToNav write FUIToNav;
property Active:Boolean read FActive write FActive;
property Capacity:Integer read FCapacity write FCapacity default 100;
property OnSaveUIState:TUIStateNotifyEvent read FOnSaveUIState write FOnSaveUIState;
property OnRetrieveUIState:TUIStateNotifyEvent read FOnRetrieveUIState write FOnRetrieveUIState;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TUIStateNav]);
end;
{ TUIStateNav }
procedure TUIStateNav.Backward;
begin
if FIndex>0 then
begin
FNavigating:=true;
FIndex:=FIndex-1;
UpdateUIState;
FNavigating:=false;
end;
end;
constructor TUIStateNav.Create(AOwner: TComponent);
begin
inherited;
Findex:=-1;
FHistory:=TList.Create;
FCapacity:=100;
end;
destructor TUIStateNav.Destroy;
var
i:integer;
aP:TPUIStateData;
begin
for i:=0 to FHistory.Count-1 do
begin
aP:=FHistory[i];
Dispose(aP);
end;
FHistory.Free;
inherited;
end;
procedure TUIStateNav.Forward;
begin
if FIndex < (FHistory.Count-1) then
begin
FNavigating:=true;
FIndex:=FIndex+1;
UpdateUIState;
FNavigating:=false;
end;
end;
function TUIStateNav.GetHistory(index: integer): TUIStateData;
var
aP:TPUIStateData;
begin
aP:=FHistory[index];
Result:=aP^;
end;
function TUIStateNav.getHistoryCount: integer;
begin
result:=FHistory.Count;
end;
procedure TUIStateNav.RecordUIState;
var
aP:TPUIStateData;
begin
if not FNavigating then
begin
if assigned(FOnSaveUIState) then
begin
new(aP);
FOnSaveUIState(self,aP);
if FHistory.Count>(FCapacity-1)then
FHistory.Delete(0);
FIndex:=FHistory.Add(aP);
end;
end;
FNavigating:=false;
end;
procedure TUIStateNav.UpdateUIState;
var
aP:TPUIStateData;
begin
FNavigating:=true;
if (FIndex>=0) and (Findex<FHistory.Count) then
begin
aP:=FHistory[FIndex];
UpdateUIStateByData(aP);
end;
FNavigating:=true;
end;
procedure TUIStateNav.UpdateUIStateByData(aUIStateData: TPUIStateData);
begin
FNavigating:=true;
if assigned(FOnRetrieveUIState) then
FOnRetrieveUIState(self,aUIStateData);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -