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

📄 hutil32.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 4 页
字号:
unit HUtil32;

//============================================
// Latest Update date : 1998 1
// Add/Update Function and procedure :
// 		CaptureString
//       Str_PCopy          	(4/29)
//			Str_PCopyEx			 	(5/2)
//			memset					(6/3)
//       SpliteBitmap         (9/3)
//       ArrestString         (10/27)  {name changed}
//       IsStringNumber       (98'1/1)
//			GetDirList				(98'12/9)
//       GetFileDate          (98'12/9)
//       CatchString          (99'2/4)
//       DivString            (99'2/4)
//       DivTailString        (99'2/4)
//       SPos                 (99'2/9)
//============================================


interface

uses
  Classes, SysUtils, StrUtils, WinTypes, WinProcs, Graphics, Messages, Dialogs;

type
  Str4096 = array[0..4096] of char;
  Str256 = array[0..256] of char;
  TyNameTable = record
    Name: string;
    varl: Longint;
  end;

  TLRect = record
    Left, Top, Right, Bottom: Longint;
  end;

const
  MAXDEFCOLOR       = 16;
  ColorNames        : array[1..MAXDEFCOLOR] of TyNameTable = (
    (Name: 'BLACK'; varl: clBlack),
    (Name: 'BROWN'; varl: clMaroon),
    (Name: 'MARGENTA'; varl: clFuchsia),
    (Name: 'GREEN'; varl: clGreen),
    (Name: 'LTGREEN'; varl: clOlive),
    (Name: 'BLUE'; varl: clNavy),
    (Name: 'LTBLUE'; varl: clBlue),
    (Name: 'PURPLE'; varl: clPurple),
    (Name: 'CYAN'; varl: clTeal),
    (Name: 'LTCYAN'; varl: clAqua),
    (Name: 'GRAY'; varl: clGray),
    (Name: 'LTGRAY'; varl: clsilver),
    (Name: 'YELLOW'; varl: clYellow),
    (Name: 'LIME'; varl: clLime),
    (Name: 'WHITE'; varl: clWhite),
    (Name: 'RED'; varl: clRed)
    );

  MAXLISTMARKER     = 3;
  LiMarkerNames     : array[1..MAXLISTMARKER] of TyNameTable = (
    (Name: 'DISC'; varl: 0),
    (Name: 'CIRCLE'; varl: 1),
    (Name: 'SQUARE'; varl: 2)
    );

  MAXPREDEFINE      = 3;
  PreDefineNames    : array[1..MAXPREDEFINE] of TyNameTable = (
    (Name: 'LEFT'; varl: 0),
    (Name: 'RIGHT'; varl: 1),
    (Name: 'CENTER'; varl: 2)
    );




function CountGarbage(paper: TCanvas; Src: PChar; TargWidth: Longint): Integer;  {garbage}
{[ArrestString]
      Result = Remain string,
      RsltStr = captured string
}
function ArrestString(Source, SearchAfter, ArrestBefore: string;
  const DropTags: array of string; var RsltStr: string): string;
{*}
function ArrestStringEx(Source, SearchAfter, ArrestBefore: string; var
  ArrestStr: string): string;
function CaptureString(Source: string; var rdstr: string): string;
procedure ClearWindow(aCanvas: TCanvas; aLeft, aTop, aRight, aBottom: Longint;
  aColor: TColor);
function CombineDirFile(SrcDir, TargName: string): string;
{*}
function CompareLStr(Src, targ: string; compn: Integer): Boolean;
function CompareBackLStr(Src, targ: string; compn: Integer): Boolean;
function CompareBuffer(p1, p2: PByte; len: Integer): Boolean;
function CreateMask(Src: PChar; TargPos: Integer): string;
procedure DrawTileImage(Canv: TCanvas; Rect: TRect; TileImage: TBitmap);
procedure DrawingGhost(Rc: TRect);
function ExtractFileNameOnly(const fname: string): string;
function FloatToString(F: Real): string;
function FloatToStrFixFmt(fVal: Double; prec, digit: Integer): string;
function FileSize(const fname: string): Longint;
{*}
function FileCopy(Source, dest: string): Boolean;
function FileCopyEx(Source, dest: string): Boolean;
function GetSpaceCount(Str: string): Longint;
function RemoveSpace(Str: string): string;
function GetFirstWord(Str: string; var sWord: string; var FrontSpace: Longint):
  string;
function GetDefColorByName(Str: string): TColor;
function GetULMarkerType(Str: string): Longint;
{*}
function GetValidStr3(Str: string; var dest: string; const Divider: array of
  char): string;
function GetValidStr4(Str: string; var dest: string; const Divider: array of
  char): string;
function GetValidStrVal(Str: string; var dest: string; const Divider: array of
  char): string;
function GetValidStrCap(Str: string; var dest: string; const Divider: array of
  char): string;
function GetStrToCoords(Str: string): TRect;
function GetDefines(Str: string): Longint;
function GetValueFromMask(Src: PChar; Mask: string): string;
procedure GetDirList(path: string; fllist: TStringList);
function GetFileDate(filename: string): Integer; //DOS format file date..
function HexToIntEx(shap_str: string): Longint;
function HexToInt(Str: string): Longint;
function IntToStrFill(num, len: Integer; fill: char): string;
function IsInB(Src: string; Pos: Integer; targ: string): Boolean;
function IsInRect(X, Y: Integer; Rect: TRect): Boolean;
function IsEnglish(Ch: char): Boolean;
function IsEngNumeric(Ch: char): Boolean;
function IsFloatNumeric(Str: string): Boolean;
function IsUniformStr(Src: string; Ch: char): Boolean;
function IsStringNumber(Str: string): Boolean;
function KillFirstSpace(var Str: string): Longint;
procedure KillGabageSpace(var Str: string);
function LRect(l, t, r, b: Longint): TLRect;
procedure MemPCopy(dest: PChar; Src: string);
procedure MemCpy(dest, Src: PChar; Count: Longint); {PChar type}
procedure memcpy2(TargAddr, SrcAddr: Longint; Count: Integer); {Longint type}
procedure memset(buffer: PChar; FillChar: char; Count: Integer);
procedure PCharSet(P: PChar; n: Integer; Ch: char);
function ReplaceChar(Src: string; srcchr, repchr: char): string;
function Str_ToDate(Str: string): TDateTime;
function Str_ToTime(Str: string): TDateTime;
function Str_ToInt(Str: string; def: Longint): Longint;
function Str_ToFloat(Str: string): Real;
function SkipStr(Src: string; const Skips: array of char): string;
procedure ShlStr(Source: PChar; Count: Integer);
procedure ShrStr(Source: PChar; Count: Integer);
procedure Str256PCopy(dest: PChar; const Src: string);
function _StrPas(dest: PChar): string;
function Str_PCopy(dest: PChar; Src: string): Integer;
function Str_PCopyEx(dest: PChar; const Src: string; buflen: Longint): Integer;
procedure SpliteBitmap(DC: HDC; X, Y: Integer; bitmap: TBitmap; transcolor:
  TColor);
procedure TiledImage(Canv: TCanvas; Rect: TLRect; TileImage: TBitmap);
function Trim_R(const Str: string): string;
function IsEqualFont(SrcFont, TarFont: TFont): Boolean;
function CutHalfCode(Str: string): string;
function ConvertToShortName(Canvas: TCanvas; Source: string; WantWidth:
  Integer): string;
{*}
function CatchString(Source: string; cap: char; var catched: string): string;
function DivString(Source: string; cap: char; var sel: string): string;
function DivTailString(Source: string; cap: char; var sel: string): string;
function SPos(substr, Str: string): Integer;
function NumCopy(Str: string): Integer;
function GetMonDay: string;
function BoolToStr(boo: Boolean): string;

function TagCount(Source: string; tag: char): Integer;
function _MIN(n1, n2: Integer): Integer;
function _MAX(n1, n2: Integer): Integer;
function CalcFileCRC(filename: string): Integer;
function IsIPaddr(IP: string): Boolean;
implementation

//var
//	CSUtilLock: TRTLCriticalSection;

function IsIPaddr(IP: string): Boolean;
var
  Node              : array[0..3] of Integer;
  tIP               : string;
  tNode             : string;
  tPos              : Integer;
  tLen              : Integer;
begin
  Result := False;
  tIP := IP;
  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[0]) then
    exit;

  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[1]) then
    exit;

  tLen := Length(tIP);
  tPos := Pos('.', tIP);
  tNode := MidStr(tIP, 1, tPos - 1);
  tIP := MidStr(tIP, tPos + 1, tLen - tPos);
  if not TryStrToInt(tNode, Node[2]) then
    exit;

  if not TryStrToInt(tIP, Node[3]) then
    exit;
  for tLen := Low(Node) to High(Node) do
  begin
    if (Node[tLen] < 0) or (Node[tLen] > 255) then
      exit;
  end;
  Result := True;
end;

function CalcFileCRC(filename: string): Integer;
begin
  try
    if not FileExists(filename) then
    begin
      Result := 0;
      exit;
    end;
    Result := 10000;

  finally
  end;
end;
{ capture "double quote streams" }

function CaptureString(Source: string; var rdstr: string): string;
var
  st, et, c, len, I : Integer;
begin
  if Source = '' then
  begin
    rdstr := '';
    Result := '';
    exit;
  end;
  c := 1;
  //et := 0;
  len := Length(Source);
  while Source[c] = ' ' do
    if c < len then
      Inc(c)
    else
      break;

  if (Source[c] = '"') and (c < len) then
  begin

    st := c + 1;
    et := len;
    for I := c + 1 to len do
      if Source[I] = '"' then
      begin
        et := I - 1;
        break;
      end;

  end
  else
  begin
    st := c;
    et := len;
    for I := c to len do
      if Source[I] = ' ' then
      begin
        et := I - 1;
        break;
      end;

  end;

  rdstr := Copy(Source, st, (et - st + 1));
  if len >= (et + 2) then
    Result := Copy(Source, et + 2, len - (et + 1))
  else
    Result := '';

end;


function CountUglyWhiteChar(sPtr: PChar): Longint;
var
  Cnt, Killw        : Longint;
begin
  Killw := 0;
  for Cnt := (StrLen(sPtr) - 1) downto 0 do
  begin
    if sPtr[Cnt] = ' ' then
    begin
      Inc(Killw);
      {sPtr[Cnt] := #0;}
    end
    else
      break;
  end;
  Result := Killw;
end;


function CountGarbage(paper: TCanvas; Src: PChar; TargWidth: Longint): Integer;  {garbage}
var
  gab, destWidth    : Integer;
begin

  gab := CountUglyWhiteChar(Src);
  destWidth := paper.TextWidth(StrPas(Src)) - gab;
  Result := TargWidth - destWidth + (gab * paper.TextWidth(' '));

end;


function GetSpaceCount(Str: string): Longint;
var
  Cnt, len, SpaceCount: Longint;
begin
  SpaceCount := 0;
  len := Length(Str);
  for Cnt := 1 to len do
    if Str[Cnt] = ' ' then
      SpaceCount := SpaceCount + 1;
  Result := SpaceCount;
end;

function RemoveSpace(Str: string): string;
var
  I                 : Integer;
begin
  Result := '';
  for I := 1 to Length(Str) do
    if Str[I] <> ' ' then
      Result := Result + Str[I];
end;

function KillFirstSpace(var Str: string): Longint;
var
  Cnt, len          : Longint;
begin
  Result := 0;
  len := Length(Str);
  for Cnt := 1 to len do
    if Str[Cnt] <> ' ' then
    begin
      Str := Copy(Str, Cnt, len - Cnt + 1);
      Result := Cnt - 1;
      break;
    end;
end;

procedure KillGabageSpace(var Str: string);
var
  Cnt, len          : Longint;
begin
  len := Length(Str);
  for Cnt := len downto 1 do
    if Str[Cnt] <> ' ' then
    begin
      Str := Copy(Str, 1, Cnt);
      KillFirstSpace(Str);
      break;
    end;
end;

function GetFirstWord(Str: string; var sWord: string; var FrontSpace: Longint):
  string;
var
  Cnt, len, n       : Longint;
  DestBuf           : Str4096;
begin
  len := Length(Str);
  if len <= 0 then
    Result := ''
  else
  begin
    FrontSpace := 0;
    for Cnt := 1 to len do
    begin
      if Str[Cnt] = ' ' then
        Inc(FrontSpace)
      else
        break;
    end;
    n := 0;
    for Cnt := Cnt to len do
    begin
      if Str[Cnt] <> ' ' then
        DestBuf[n] := Str[Cnt]
      else
      begin
        DestBuf[n] := #0;
        sWord := StrPas(DestBuf);
        Result := Copy(Str, Cnt, len - Cnt + 1);
        exit;
      end;
      Inc(n);
    end;
    DestBuf[n] := #0;
    sWord := StrPas(DestBuf);
    Result := '';
  end;
end;

function HexToIntEx(shap_str: string): Longint;
begin
  Result := HexToInt(Copy(shap_str, 2, Length(shap_str) - 1));
end;

function HexToInt(Str: string): Longint;
var
  digit             : char;
  Count, I          : Integer;
  Cur, Val          : Longint;
begin
  Val := 0;
  Count := Length(Str);
  for I := 1 to Count do
  begin
    digit := Str[I];
    if (digit >= '0') and (digit <= '9') then
      Cur := Ord(digit) - Ord('0')
    else if (digit >= 'A') and (digit <= 'F') then
      Cur := Ord(digit) - Ord('A') + 10
    else if (digit >= 'a') and (digit <= 'f') then
      Cur := Ord(digit) - Ord('a') + 10
    else
      Cur := 0;
    Val := Val + (Cur shl (4 * (Count - I)));
  end;
  Result := Val;
  //   Result := (Val and $0000FF00) or ((Val shl 16) and $00FF0000) or ((Val shr 16) and $000000FF);
end;

function Str_ToInt(Str: string; def: Longint): Longint;
begin
  Result := def;
  if Str <> '' then
  begin
    if ((Word(Str[1]) >= Word('0')) and (Word(Str[1]) <= Word('9'))) or
      (Str[1] = '+') or (Str[1] = '-') then
    try
      Result := StrToInt64(Str);
    except
    end;
  end;
end;

function Str_ToDate(Str: string): TDateTime;
begin
  if Trim(Str) = '' then
    Result := Date
  else
    Result := StrToDate(Str);
end;

function Str_ToTime(Str: string): TDateTime;
begin
  if Trim(Str) = '' then
    Result := Time
  else
    Result := StrToTime(Str);
end;

function Str_ToFloat(Str: string): Real;
begin
  if Str <> '' then
  try
    Result := StrToFloat(Str);
    exit;
  except
  end;
  Result := 0;
end;

procedure DrawingGhost(Rc: TRect);
var
  DC                : HDC;
begin
  DC := GetDC(0);
  DrawFocusRect(DC, Rc);
  ReleaseDC(0, DC);
end;

function ExtractFileNameOnly(const fname: string): string;
var
  extpos            : Integer;
  ext, fn           : string;
begin
  ext := ExtractFileExt(fname);
  fn := ExtractFileName(fname);
  if ext <> '' then
  begin
    extpos := Pos(ext, fn);
    Result := Copy(fn, 1, extpos - 1);
  end
  else
    Result := fn;
end;

function FloatToString(F: Real): string;
begin
  Result := FloatToStrFixFmt(F, 5, 2);
end;

function FloatToStrFixFmt(fVal: Double; prec, digit: Integer): string;
var
  Cnt, dest, len, I, j: Integer;
  fstr              : string;
  Buf               : array[0..255] of char;
label
  end_conv;
begin
  Cnt := 0;
  dest := 0;
  fstr := FloatToStrF(fVal, ffGeneral, 15, 3);
  len := Length(fstr);
  for I := 1 to len do
  begin
    if fstr[I] = '.' then
    begin
      Buf[dest] := '.';
      Inc(dest);
      Cnt := 0;
      for j := I + 1 to len do
      begin
        if Cnt < digit then
        begin
          Buf[dest] := fstr[j];
          Inc(dest);
        end
        else
        begin
          goto end_conv;
        end;
        Inc(Cnt);
      end;
      goto end_conv;
    end;
    if Cnt < prec then
    begin
      Buf[dest] := fstr[I];
      Inc(dest);
    end;
    Inc(Cnt);
  end;
  end_conv:
  Buf[dest] := char(0);
  Result := StrPas(Buf);
end;


function FileSize(const fname: string): Longint;
var
  SearchRec         : TSearchRec;
begin
  if FindFirst(ExpandFileName(fname), faAnyFile, SearchRec) = 0 then
    Result := SearchRec.Size
  else
    Result := -1;
end;


function FileCopy(Source, dest: string): Boolean;
var
  fSrc, fDst, len   : Integer;
  Size              : Longint;
  buffer            : packed array[0..2047] of Byte;
begin
  Result := False;                      { Assume that it WONT work }
  if Source <> dest then
  begin
    fSrc := FileOpen(Source, fmOpenRead);

⌨️ 快捷键说明

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