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

📄 misc.pas

📁 帮助编写程序
💻 PAS
字号:
unit Misc;

interface

uses
  Windows, Messages, SysUtils, Classes, Forms, Controls, ShellAPI;

procedure MsgDlgError(const Handle: THandle; const Text: string);
procedure MsgDlgInfo(const Handle: THandle; const Text: string);
function MsgDlgQuery(const Handle: THandle; const Text: string): Boolean;
function GetWindowsDir: string;
function GetWinTempDir: string;
function AddDirSuffix(Dir: string): string;
procedure BeginWait;
procedure EndWait;
function BackDir(dir: string): string;
function BetweenString(const what, begins, ends: string): string;
procedure OpenLink(const link: string);
function myGetFileSize(const FileName: string): LongInt;

implementation

{弹出错误信息框}

procedure MsgDlgError(const Handle: THandle; const Text: string);
begin
  MessageBox(Handle, PChar(Text), PChar(Application.Title), MB_OK + MB_ICONSTOP + MB_TOPMOST);
end;

{弹出提示信息框}

procedure MsgDlgInfo(const Handle: THandle; const Text: string);
begin
  MessageBox(Handle, PChar(Text), PChar(Application.Title), MB_OK + MB_ICONINFORMATION + MB_TOPMOST);
end;

{弹出选择框}

function MsgDlgQuery(const Handle: THandle; const Text: string): Boolean;
begin
  Result := MessageBox(Handle, PChar(Text), PChar(Application.Title), MB_YESNO + MB_ICONQUESTION + MB_TOPMOST) = mrYES;
end;

function GetWindowsDir: string;
var
  Buf: array[0..MAX_PATH] of Char;
begin
  GetWindowsDirectory(Buf, MAX_PATH);
  Result := AddDirSuffix(Buf);
end;

function GetWinTempDir: string;
var
  Buf: array[0..MAX_PATH] of Char;
begin
  GetTempPath(MAX_PATH, Buf);
  Result := AddDirSuffix(Buf);
end;

function AddDirSuffix(Dir: string): string;
begin
  Result := Trim(Dir);
  if Result = '' then exit;
  if Result[Length(Result)] <> '\' then Result := Result + '\';
end;

procedure BeginWait;
begin
  Screen.Cursor := crHourGlass;
end;

procedure EndWait;
begin
  Screen.Cursor := crDefault;
end;

//后退目录名,如:
// C:\Windows\system32\  ->  C:\Windows\

function BackDir(dir: string): string;
var
  i: Integer;
begin
  for i := Length(dir) - 2 downto 0 do
    if dir[i] = '\' then
      break;
  SetLength(dir, i);
  Result := dir;
end;

//获得字符串,去首尾,返回中间的部分。如:
// BetweenString('<xX>yyy</Xx>', '<xX>', '</Xx>')  ->  yyy
//注意:只返回第一个最近的匹配

function BetweenString(const what, begins, ends: string): string;
var
  b: Integer;
  s: string;
begin
  b := Pos(begins, what);
  if b <> 0 then
  begin
    Inc(b, Length(begins));
    s := Copy(what, b, Length(what));
    Result := Copy(what, b, Pos(ends, s) - 1);
  end
  else
    Result := '';
end;

procedure OpenLink(const link: string);
begin
  ShellExecute(0, 'open', PChar(link), nil, nil, SW_SHOWNORMAL);
end;

function myGetFileSize(const FileName: string): LongInt;
var
  SearchRec: TSearchRec;
begin
  try
    if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then
      Result := SearchRec.Size
    else Result := -1;
  finally
    SysUtils.FindClose(SearchRec);
  end;
end;

end.

⌨️ 快捷键说明

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