📄 upagemanage.pas
字号:
unit uPageManage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, RzTabs, uBaseForm;
type
TPageManage = class
private
FCount: Integer;
FPageControl: TRzPageControl;
function GetPage(Index: Integer): TBaseForm;
function GetCount: Integer;
function GetPageName(Index: Integer): string;
procedure SetPageName(Index: Integer; Value: string);
function GetActivePage: TBaseForm;
function GetActivePageType: TFormType;
function GetActivePageIndex: Integer;
public
constructor Create(aPageControl: TRzPageControl); // override;
destructor Destroy; override;
procedure Add(Item: Pointer; aPageName: string);
procedure Delete(index: Integer);
procedure Clear;
property Count: Integer read GetCount;
property Pages[Index: Integer]: TBaseForm read GetPage;
property PageName[Index: Integer]: string read GetPageName write SetPageName;
property ActivePage: TBaseForm read GetActivePage;
property ActivePageType: TFormType read GetActivePageType;
property ActivePageIndex: Integer read GetActivePageIndex;
end;
implementation
{ TPageBrowseManage }
constructor TPageManage.Create(aPageControl: TRzPageControl);
begin
inherited Create;
FCount := 0;
FPageControl := aPageControl;
end;
destructor TPageManage.Destroy;
begin
Clear;
inherited Destroy;
end;
procedure TPageManage.Add(Item: Pointer; aPageName: string);
var
tabSheet: TRzTabSheet;
begin
if Item = nil then Exit;
Inc(FCount);
tabSheet := TRzTabSheet.Create(nil);
{设置页面标题 }
if aPageName = '' then
tabSheet.Caption := TBaseForm(Item).Caption
else
tabSheet.Caption := aPageName;
tabSheet.PageControl := FPageControl;
tabSheet.Data := nil;
tabSheet.Data := Item;
TBaseForm(Item).Parent := TabSheet;
TBaseForm(Item).Align := alClient;
TBaseForm(Item).Show; {显示窗体}
FPageControl.ActivePage := tabSheet; {设置当前活动页面 }
end;
{删除页面}
procedure TPageManage.Delete(index: Integer);
var
TempItem: Pointer;
tabSheet: TRzTabSheet;
begin
tabSheet := FPageControl.Pages[index];
TempItem := tabSheet.Data;
{释放FORM}
if Assigned(TempItem) then
begin
TBaseForm(TempItem).Free;
end;
{删除页面}
tabSheet.PageControl := nil;
tabSheet.Free;
Dec(FCount);
{设置下一个活动页面 }
if (FCount > index) and (FCount > 0) then
begin
FPageControl.ActivePageIndex := index;
end
else
begin
if FCount <> 0 then
FPageControl.ActivePageIndex := Count - 1;
end;
end;
procedure TPageManage.Clear;
var
TempItem: Pointer;
tabSheet: TRzTabSheet;
begin
while FCount > 0 do
begin
tabSheet := FPageControl.Pages[0];
TempItem := tabSheet.Data;
{释放FORM}
if Assigned(TempItem) then
begin
//TBaseBrowseForm(TempItem).Free;
FreeAndNil(TempItem);
end;
{删除页面}
tabSheet.PageControl := nil;
tabSheet.Free;
Dec(FCount);
end;
FCount := 0;
end;
function TPageManage.GetPage(Index: Integer): TBaseForm;
begin
Result := TBaseForm(FPageControl.Pages[index].Data);
end;
function TPageManage.GetPageName(index: Integer): string;
begin
Result := FPageControl.Pages[index].Caption;
end;
procedure TPageManage.SetPageName(index: Integer; Value: string);
begin
FPageControl.Pages[index].Caption := Value;
end;
function TPageManage.GetCount: Integer;
begin
Result := FCount;
end;
function TPageManage.GetActivePage: TBaseForm;
begin
if FCount > 0 then
Result := Pages[ActivePageIndex]
else
Result := nil;
end;
function TPageManage.GetActivePageType: TFormType;
begin
Result := ActivePage.FormType;
end;
function TPageManage.GetActivePageIndex: Integer;
begin
if FPageControl.ActivePageIndex > 0 then
Result := FPageControl.ActivePageIndex
else
Result := 0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -