📄 general.pas
字号:
unit General;
interface
uses
Windows;
const
MSGTITLE_ASK = '系统提示';
MSGTITLE_ALARM = '警告';
MSGTITLE_ERR = '错误';
MSGFLAG_ASK = MB_YESNO + MB_ICONQUESTION;
MSGFLAG_ALARM = MB_YESNO + MB_ICONWARNING;
MSGFLAG_ERR = MB_OK + MB_ICONERROR;
function ConfirmBox(AMsg: string): Boolean; overload;
function ConfirmBox(AMsg: string; AWnd: THandle): Boolean; overload;
function AlarmBox(AMsg: string): Boolean; overload;
function AlarmBox(AMsg: string; AWnd: THandle): Boolean; overload;
procedure ErrorBox(AMsg: string); overload;
procedure ErrorBox(AMsg: string; AWnd: THandle); overload;
function ByteArrayEqual(AArr1, AArr2: array of Byte): Boolean;
procedure BytesToHexString(const ABytes; ALen: integer; var AResult: string);
function ArrPos(subStr: string; var source: array of Char): integer;
implementation
function ConfirmBox(AMsg: string): Boolean;
begin
Result := ID_YES = MessageBox(0, PChar(AMsg), MSGTITLE_ASK, MSGFLAG_ASK);
end;
function ConfirmBox(AMsg: string; AWnd: THandle): Boolean;
begin
Result := ID_YES = MessageBox(AWnd, PChar(AMsg), MSGTITLE_ASK, MSGFLAG_ASK);
end;
function AlarmBox(AMsg: string): Boolean; overload;
begin
Result := ID_YES = MessageBox(0, PChar(AMsg), MSGTITLE_ALARM, MSGFLAG_ALARM);
end;
function AlarmBox(AMsg: string; AWnd: THandle): Boolean; overload;
begin
Result := ID_YES = MessageBox(0, PChar(AMsg), MSGTITLE_ALARM, MSGFLAG_ALARM);
end;
procedure ErrorBox(AMsg: string); overload;
begin
MessageBox(0, PChar(AMsg), MSGTITLE_ERR, MSGFLAG_ERR);
end;
procedure ErrorBox(AMsg: string; AWnd: THandle); overload;
begin
MessageBox(AWnd, PChar(AMsg), MSGTITLE_ERR, MSGFLAG_ERR);
end;
function ByteArrayEqual(AArr1, AArr2: array of Byte): Boolean;
var
i: integer;
begin
Result := False;
if (Low(AArr1) = Low(AArr2)) and (High(AArr1) = High(AArr2)) then begin
for i := Low(AArr1) to High(AArr1) do
if AArr1[i] <> AArr2[i] then
Exit;
Result := True;
end;
end;
procedure BytesToHexString(const ABytes; ALen: integer; var AResult: string);
var
p: PByte;
pc: PChar;
i: integer;
const
hx: array[0..15] of Char = '0123456789ABCDEF';
begin
GetMem(pc, ALen * 2 + 1);
p := PByte(@ABytes);
for i := 0 to ALen - 1 do begin
pc[i * 2] := hx[p^ and 240 shr 4];
pc[i * 2 + 1] := hx[p^ and 15];
Inc(p);
end;
pc[ALen * 2] := #0;
AResult := pc;
FreeMem(pc, ALen * 2 + 1);
end;
function ArrPos(subStr: string; var source: array of Char): integer;
var
i, j: integer;
sLen, aLow, aHigh: integer;
begin
Result := -1;
sLen := Length(subStr);
if sLen < 1 then
Exit;
aLow := Low(source);
aHigh := High(source);
for i := aLow to aHigh do begin
if source[i] = subStr[1] then begin
Result := i;
for j := 1 to sLen do begin
if source[i + j - 1] <> subStr[j] then begin
Result := -1;
break;
end;
end;
if Result >= 0 then
break;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -