📄 mruunit.pas
字号:
//---------------------------------------------------------------------------
//(R)CopyRight KivenSoft International ,inc 1999
//单元名称:最近开启文件列表类
//程序名称:电子书库
//作 者:李会文
//开始时间:1999.07.06
//最后修改:1999.07.06
//备注:此单元定义了最近开启的文件列表类
//---------------------------------------------------------------------------
unit MruUnit;
interface
uses
Menus;
type
TMru=class
private
FFileList:array[0..4]of string;
FListIndex:array[0..4]of integer;
FParentMenu:TMenuItem;
FPosition:integer;
FVisible:boolean;
function GetFileList(index:integer):string;
procedure SetFileList(index:integer;Value:string);
procedure SetVisible(Value:boolean);
public
constructor Create;
destructor Destroy;override;
procedure Add(Fn:string);
property FileList[index:integer]:string read GetFileList write SetFileList;default;
property ParentMenu:TMenuItem read FParentMenu write FParentMenu;
property Position:integer read FPosition write FPosition;
property Visible:boolean read FVisible write SetVisible;
end;
var
Mru:TMru;
implementation
constructor TMru.Create;
var
i:integer;
begin
for i:=0 to 4 do
begin
FFileList[i]:='';
FListIndex[i]:=i;
end;
FParentMenu:=nil;
FPosition:=0;
FVisible:=true;
end;
destructor TMru.Destroy;
begin
inherited Destroy;
end;
procedure TMru.Add(Fn:string);
var
i,j,k:integer;
begin
{$ifdef debug}
if FParentMenu=nil then raise Exception.Create('Error in TMru.InsertToMenu');
{$endif}
if FFileList[FListIndex[0]]=Fn then exit;
j:=-1;
for i:=1 to 4 do
if FFileList[FListIndex[i]]=Fn then j:=i;
if j=-1 then
begin
k:=FListIndex[4]; //保存最后串索引
FFileList[k]:=Fn; //更新最后串
for i:=4 downto 1 do FListIndex[i]:=FListIndex[i-1];
FListIndex[0]:=k; //置最后串到最前
end
else
begin
k:=FListIndex[j];
for i:=j downto 1 do FListIndex[i]:=FListIndex[i-1];
FListIndex[0]:=k;
end;
if FVisible then
for i:=0 to 4 do
with FParentMenu do
begin
if FFileList[FListIndex[i]]<>'' then
begin
Items[Position+i].Caption:='&1 '+FFileList[FListIndex[i]];
Items[Position+i].Visible:=true;
end
else
begin
Items[Position+i].Visible:=false;
end;
end;
end;
function TMru.GetFileList(index:integer):string;
begin
Result:=FFileList[FListIndex[index]];
end;
procedure TMru.SetFileList(index:integer;Value:string);
begin
FFileList[FListIndex[index]]:=Value;
end;
procedure TMru.SetVisible(Value:boolean);
var
i:integer;
begin
FVisible:=Value;
with FParentMenu do
begin
if Value then
begin
for i:=0 to 4 do
if FFileList[FListIndex[i]]<>'' then Items[Position+i].Visible:=true
else Items[Position+i].Visible:=false;
end
else
begin
for i:=0 to 4 do Items[Position+i].Visible:=Value;
end;
Items[Position+5].Visible:=Value;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -