⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mrumgr.pas

📁 === === === MiniHex 1.61 源程序说明 ============================== “$(MiniHex)Source”目录中的所有
💻 PAS
字号:

{**********************************************************}
{                                                          }
{  MRU Manager Class                                       }
{  Modify Date List:                                       }
{      - 2003.12.25                                        }
{      - 2001.8.28                                         }
{                                                          }
{**********************************************************}

unit MRUMgr;

interface

uses
  Windows, Messages, SysUtils, Classes, Forms, IniFiles;

//API declare 
function PathCompactPathEx(pszOut: LPSTR; pszSrc: LPCSTR; cchMax: UINT; dwFlags: DWORD): BOOL; stdcall; external 'shlwapi.dll' name 'PathCompactPathExA';

const
  MRU_DefaultDispLength = 30;
  MRU_IniSectionName = 'MRU';
  MRU_DefItemCount = 4;

type
  TMRUMgr = class(TObject)
  private
    FIniFileName: string;
    FItems: TStrings;

  public
    constructor Create(IniFileName: string);
    destructor Destroy; override;

    procedure AddMRU(Item: string);
    procedure ReadMRU(var Items: TStrings);
    procedure WriteMRU(Items: TStrings);
    function GetDisplayString(Index: Integer; MaxLen: Integer = MRU_DefaultDispLength): string;

    property Items: TStrings read FItems;
  end;

var
  MRUManager: TMRUMgr;

implementation

uses Misc;

constructor TMRUMgr.Create(IniFileName: string);
begin
  FIniFileName := IniFileName;
  FItems := TStringList.Create;
  ReadMRU(FItems);
end;

destructor TMRUMgr.Destroy; 
begin
  FItems.Free;
end;

procedure TMRUMgr.AddMRU(Item: string);
var
  I: Integer;
begin
  I := FItems.IndexOf(Item);
  if I <> -1 then FItems.Delete(I);

  if FItems.Count < MRU_DefItemCount then FItems.Add('');
  for I := FItems.Count - 1 downto 1 do
    FItems[I] := FItems[I - 1];
  FItems[0] := Item;
  WriteMRU(FItems);
end;

procedure TMRUMgr.ReadMRU(var Items: TStrings);
var
  Ini: TIniFile;
  I: Integer;
  S: string;
begin
  Ini := TIniFile.Create(FIniFileName);
  try
    Items.Clear;
    for I := 1 to MRU_DefItemCount do
    begin
      S := Ini.ReadString(MRU_IniSectionName, 'File' + IntToStr(I), '');
      if S <> '' then Items.Add(S);
    end;
  finally
    Ini.Free;
  end;
end;

procedure TMRUMgr.WriteMRU(Items: TStrings);
var
  Ini: TIniFile;
  I: Integer;
begin
  Ini := TIniFile.Create(FIniFileName);
  try
    Ini.EraseSection(MRU_IniSectionName);
    for I := 0 to Items.Count - 1 do
      Ini.WriteString(MRU_IniSectionName, 'File' + IntToStr(I+1), Items[I]);
  finally
    Ini.Free;
  end;
end;

function TMRUMgr.GetDisplayString(Index: Integer; MaxLen: Integer): string;
const
  MaxSize = 255;
var
  DstBuf: array[0..MaxSize] of Char;
begin
  if MaxLen > MaxSize then MaxLen := MaxSize;
  PathCompactPathEx(DstBuf, PChar(Items[Index]), MaxLen, 0);
  Result := DstBuf;
end;

end.

⌨️ 快捷键说明

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