mru.pas

来自「这是一个DELPHI7应用案例开发篇有配套程序种子光盘」· PAS 代码 · 共 66 行

PAS
66 行
字号
unit MRU;

interface

uses
    Classes, SysUtils;

type
  TMRUList = class
  private
    FFiles:TStringList;
    FMaxCount : Integer;
  public
    constructor Create(MaxCount:Integer);
    procedure AddFile(AFileName:String);
    function GetList:TStringList;
  end;

implementation

{ TMRUList }

procedure TMRUList.AddFile(AFileName: String);
var
    i:Integer;
begin
    i := FFiles.IndexOf(AFileName);
    if i= -1 then
    begin
        if FFiles.Count = FMaxCount then
        begin
            FFiles.Delete(FMaxCount-1);
            FFiles.Insert(0,AFileName);
        end
        else
            FFiles.Insert(0,AFileName);
    end
    else
    begin
        FFiles.Delete(i);
        FFiles.Insert(0,AFileName);
    end;
end;

constructor TMRUList.Create(MaxCount:Integer);
begin
    inherited Create;

    if (MaxCount<2) or (MaxCount>10) then
        raise ERangeError.Create('Max MRU Count should locate in [2,10]');

    FMaxCount := MaxCount;

    FFiles := TStringList.Create;
    FFiles.CaseSensitive := False;
    FFiles.Duplicates := dupIgnore;
    FFiles.Sorted := False;
end;

function TMRUList.GetList: TStringList;
begin
    Result := FFiles;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?