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

📄 hutil32.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    if fSrc >= 0 then
    begin
      Size := FileSeek(fSrc, 0, 2);
      FileSeek(fSrc, 0, 0);
      fDst := FileCreate(dest);
      if fDst >= 0 then
      begin
        while Size > 0 do
        begin
          len := FileRead(fSrc, buffer, SizeOf(buffer));
          FileWrite(fDst, buffer, len);
          Size := Size - len;
        end;
        FileSetDate(fDst, FileGetDate(fSrc));
        FileClose(fDst);
        FileSetAttr(dest, FileGetAttr(Source));
        Result := True;
      end;
      FileClose(fSrc);
    end;
  end;
end;

function FileCopyEx(Source, dest: string): Boolean;
var
  fSrc, fDst, len   : Integer;
  Size              : Longint;
  buffer            : array[0..512000] of Byte;
begin
  Result := False;                      { Assume that it WONT work }
  if Source <> dest then
  begin
    fSrc := FileOpen(Source, fmOpenRead or fmShareDenyNone);
    if fSrc >= 0 then
    begin
      Size := FileSeek(fSrc, 0, 2);
      FileSeek(fSrc, 0, 0);
      fDst := FileCreate(dest);
      if fDst >= 0 then
      begin
        while Size > 0 do
        begin
          len := FileRead(fSrc, buffer, SizeOf(buffer));
          FileWrite(fDst, buffer, len);
          Size := Size - len;
        end;
        FileSetDate(fDst, FileGetDate(fSrc));
        FileClose(fDst);
        FileSetAttr(dest, FileGetAttr(Source));
        Result := True;
      end;
      FileClose(fSrc);
    end;
  end;
end;


function GetDefColorByName(Str: string): TColor;
var
  Cnt               : Integer;
  COmpStr           : string;
begin
  COmpStr := UpperCase(Str);
  for Cnt := 1 to MAXDEFCOLOR do
  begin
    if COmpStr = ColorNames[Cnt].Name then
    begin
      Result := TColor(ColorNames[Cnt].varl);
      exit;
    end;
  end;
  Result := $0;
end;

function GetULMarkerType(Str: string): Longint;
var
  Cnt               : Integer;
  COmpStr           : string;
begin
  COmpStr := UpperCase(Str);
  for Cnt := 1 to MAXLISTMARKER do
  begin
    if COmpStr = LiMarkerNames[Cnt].Name then
    begin
      Result := LiMarkerNames[Cnt].varl;
      exit;
    end;
  end;
  Result := 1;
end;

function GetDefines(Str: string): Longint;
var
  Cnt               : Integer;
  COmpStr           : string;
begin
  COmpStr := UpperCase(Str);
  for Cnt := 1 to MAXPREDEFINE do
  begin
    if COmpStr = PreDefineNames[Cnt].Name then
    begin
      Result := PreDefineNames[Cnt].varl;
      exit;
    end;
  end;
  Result := -1;
end;

procedure ClearWindow(aCanvas: TCanvas; aLeft, aTop, aRight, aBottom: Longint;
  aColor: TColor);
begin
  with aCanvas do
  begin
    Brush.Color := aColor;
    Pen.Color := aColor;
    Rectangle(0, 0, aRight - aLeft, aBottom - aTop);
  end;
end;


procedure DrawTileImage(Canv: TCanvas; Rect: TRect; TileImage: TBitmap);
var
  I, j, ICnt, JCnt, BmWidth, BmHeight: Integer;
begin

  BmWidth := TileImage.Width;
  BmHeight := TileImage.Height;
  ICnt := ((Rect.Right - Rect.Left) + BmWidth - 1) div BmWidth;
  JCnt := ((Rect.Bottom - Rect.Top) + BmHeight - 1) div BmHeight;

  UnrealizeObject(Canv.Handle);
  SelectPalette(Canv.Handle, TileImage.Palette, False);
  RealizePalette(Canv.Handle);

  for j := 0 to JCnt do
  begin
    for I := 0 to ICnt do
    begin

      { if (I * BmWidth) < (Rect.Right-Rect.Left) then
         BmWidth := TileImage.Width else
          BmWidth := (Rect.Right - Rect.Left) - ((I-1) * BmWidth);

       if (
       BmWidth := TileImage.Width;
       BmHeight := TileImage.Height;  }

      BitBlt(Canv.Handle,
        Rect.Left + I * BmWidth,
        Rect.Top + (j * BmHeight),
        BmWidth,
        BmHeight,
        TileImage.Canvas.Handle,
        0,
        0,
        SRCCOPY);

    end;
  end;

end;


procedure TiledImage(Canv: TCanvas; Rect: TLRect; TileImage: TBitmap);
var
  I, j, ICnt, JCnt, BmWidth, BmHeight: Integer;
  Rleft, RTop, RWidth, RHeight, BLeft, BTop: Longint;
begin

  if Assigned(TileImage) then
    if TileImage.Handle <> 0 then
    begin

      BmWidth := TileImage.Width;
      BmHeight := TileImage.Height;
      ICnt := (Rect.Right + BmWidth - 1) div BmWidth - (Rect.Left div BmWidth);
      JCnt := (Rect.Bottom + BmHeight - 1) div BmHeight - (Rect.Top div
        BmHeight);

      UnrealizeObject(Canv.Handle);
      SelectPalette(Canv.Handle, TileImage.Palette, False);
      RealizePalette(Canv.Handle);

      for j := 0 to JCnt do
      begin
        for I := 0 to ICnt do
        begin

          if I = 0 then
          begin
            BLeft := Rect.Left - ((Rect.Left div BmWidth) * BmWidth);
            Rleft := Rect.Left;
            RWidth := BmWidth;
          end
          else
          begin
            if I = ICnt then
              RWidth := Rect.Right - ((Rect.Right div BmWidth) * BmWidth)
            else
              RWidth := BmWidth;
            BLeft := 0;
            Rleft := (Rect.Left div BmWidth) + (I * BmWidth);
          end;


          if j = 0 then
          begin
            BTop := Rect.Top - ((Rect.Top div BmHeight) * BmHeight);
            RTop := Rect.Top;
            RHeight := BmHeight;
          end
          else
          begin
            if j = JCnt then
              RHeight := Rect.Bottom - ((Rect.Bottom div BmHeight) * BmHeight)
            else
              RHeight := BmHeight;
            BTop := 0;
            RTop := (Rect.Top div BmHeight) + (j * BmHeight);
          end;

          BitBlt(Canv.Handle,
            Rleft,
            RTop,
            RWidth,
            RHeight,
            TileImage.Canvas.Handle,
            BLeft,
            BTop,
            SRCCOPY);

        end;
      end;

    end;
end;


function GetValidStr3(Str: string; var dest: string; const Divider: array of
  char): string;
const
  BUF_SIZE          = 20480;            //$7FFF;
var
  Buf               : array[0..BUF_SIZE] of char;
  BufCount, Count, SrcLen, I, ArrCount: Longint;
  Ch                : char;
label
  CATCH_DIV;
begin
  Ch := #0;                             //Jacky
  try
    SrcLen := Length(Str);
    BufCount := 0;
    Count := 1;

    if SrcLen >= BUF_SIZE - 1 then
    begin
      Result := '';
      dest := '';
      exit;
    end;

    if Str = '' then
    begin
      dest := '';
      Result := Str;
      exit;
    end;
    ArrCount := SizeOf(Divider) div SizeOf(char);

    while True do
    begin
      if Count <= SrcLen then
      begin
        Ch := Str[Count];
        for I := 0 to ArrCount - 1 do
          if Ch = Divider[I] then
            goto CATCH_DIV;
      end;
      if (Count > SrcLen) then
      begin
        CATCH_DIV:
        if (BufCount > 0) then
        begin
          if BufCount < BUF_SIZE - 1 then
          begin
            Buf[BufCount] := #0;
            dest := string(Buf);
            Result := Copy(Str, Count + 1, SrcLen - Count);
          end;
          break;
        end
        else
        begin
          if (Count > SrcLen) then
          begin
            dest := '';
            Result := Copy(Str, Count + 2, SrcLen - 1);
            break;
          end;
        end;
      end
      else
      begin
        if BufCount < BUF_SIZE - 1 then
        begin
          Buf[BufCount] := Ch;
          Inc(BufCount);
        end;                            // else
        //ShowMessage ('BUF_SIZE overflow !');
      end;
      Inc(Count);
    end;
  except
    dest := '';
    Result := '';
  end;
end;


// 备盒巩磊啊 唱赣瘤(Result)俊 器窃 等促.

function GetValidStr4(Str: string; var dest: string; const Divider: array of
  char): string;
const
  BUF_SIZE          = 18200;            //$7FFF;
var
  Buf               : array[0..BUF_SIZE] of char;
  BufCount, Count, SrcLen, I, ArrCount: Longint;
  Ch                : char;
label
  CATCH_DIV;
begin
  Ch := #0;                             //Jacky
  try
    //EnterCriticalSection (CSUtilLock);
    SrcLen := Length(Str);
    BufCount := 0;
    Count := 1;

    if Str = '' then
    begin
      dest := '';
      Result := Str;
      exit;
    end;
    ArrCount := SizeOf(Divider) div SizeOf(char);

    while True do
    begin
      if Count <= SrcLen then
      begin
        Ch := Str[Count];
        for I := 0 to ArrCount - 1 do
          if Ch = Divider[I] then
            goto CATCH_DIV;
      end;
      if (Count > SrcLen) then
      begin
        CATCH_DIV:
        if (BufCount > 0) or (Ch <> ' ') then
        begin
          if BufCount <= 0 then
          begin
            Buf[0] := Ch;
            Buf[1] := #0;
            Ch := ' ';
          end
          else
            Buf[BufCount] := #0;
          dest := string(Buf);
          if Ch <> ' ' then
            Result := Copy(Str, Count, SrcLen - Count + 1)  //remain divider in rest-string,
          else
            Result := Copy(Str, Count + 1, SrcLen - Count); //exclude whitespace
          break;
        end
        else
        begin
          if (Count > SrcLen) then
          begin
            dest := '';
            Result := Copy(Str, Count + 2, SrcLen - 1);
            break;
          end;
        end;
      end
      else
      begin
        if BufCount < BUF_SIZE - 1 then
        begin
          Buf[BufCount] := Ch;
          Inc(BufCount);
        end
        else
          ShowMessage('BUF_SIZE overflow !');
      end;
      Inc(Count);
    end;
  finally
    //LeaveCriticalSection (CSUtilLock);
  end;
end;


function GetValidStrVal(Str: string; var dest: string; const Divider: array of
  char): string;
//箭磊甫 盒府秦晨 ex) 12.30mV
const
  BUF_SIZE          = 15600;
var
  Buf               : array[0..BUF_SIZE] of char;
  BufCount, Count, SrcLen, I, ArrCount: Longint;
  Ch                : char;
  currentNumeric    : Boolean;
  hexmode           : Boolean;
label
  CATCH_DIV;
begin
  Ch := #0;                             //Jacky
  try
    //EnterCriticalSection (CSUtilLock);
    hexmode := False;
    SrcLen := Length(Str);
    BufCount := 0;
    Count := 1;
    currentNumeric := False;

    if Str = '' then
    begin
      dest := '';
      Result := Str;
      exit;
    end;
    ArrCount := SizeOf(Divider) div SizeOf(char);

    while True do
    begin
      if Count <= SrcLen then
      begin
        Ch := Str[Count];
        for I := 0 to ArrCount - 1 do
          if Ch = Divider[I] then
            goto CATCH_DIV;
      end;
      if not currentNumeric then
      begin
        if (Count + 1) < SrcLen then
        begin
          if (Str[Count] = '0') and (UpCase(Str[Count + 1]) = 'X') then
          begin
            Buf[BufCount] := Str[Count];
            Buf[BufCount + 1] := Str[Count + 1];
            Inc(BufCount, 2);
            Inc(Count, 2);
            hexmode := True;
            currentNumeric := True;
            Continue;
          end;
          if (Ch = '-') and (Str[Count + 1] >= '0') and (Str[Count + 1] <= '9')
            then
          begin
            currentNumeric := True;
          end;
        end;
        if (Ch >= '0') and (Ch <= '9') then
        begin
          currentNumeric := True;
        end;
      end
      else
      begin
        if hexmode then
        begin
          if not (((Ch >= '0') and (Ch <= '9')) or
            ((Ch >= 'A') and (Ch <= 'F')) or
            ((Ch >= 'a') and (Ch <= 'f'))) then
          begin
            Dec(Count);
            goto CATCH_DIV;
          end;
        end
        else if ((Ch < '0') or (Ch > '9')) and (Ch <> '.') then
        begin
          Dec(Count);
          goto CATCH_DIV;
        end;
      end;
      if (Count > SrcLen) then
      begin
        CATCH_DIV:
        if (BufCount > 0) then
        begin
          Buf[BufCount] := #0;
          dest := string(Buf);
          Result := Copy(Str, Count + 1, SrcLen - Count);
          break;
        end
        else
        begin
          if (Count > SrcLen) then
          begin
            dest := '';
            Result := Copy(Str, Count + 2, SrcLen - 1);
            break;
          end;
        end;
      end
      else
      begin
        if BufCount < BUF_SIZE - 1 then
        begin
          Buf[BufCount] := Ch;
          Inc(BufCount);
        end
        else
          ShowMessage('BUF_SIZE overflow !');
      end;
      Inc(Count);
    end;
  finally
    //LeaveCriticalSection (CSUtilLock);
  end;
end;

{" " capture => CaptureString (source: string; var rdstr: string): string;
 ** 贸澜俊 " 绰 亲惑 盖 贸澜俊 乐促绊 啊沥
}

function GetValidStrCap(Str: string; var dest: string; const Divider: array of
  char): string;
begin
  Str := TrimLeft(Str);
  if Str <> '' then
  begin
    if Str[1] = '"' then
      Result := CaptureString(Str, dest)
    else
    begin
      Result := GetValidStr3(Str, dest, Divider);
    end;
  end
  else
  begin
    Result := '';
    dest := '';
  end;
end;


function IntToStrFill(num, len: Integer; fill: char): string;
var
  I                 : Integer;
  Str               : string;
begin
  Result := '';
  Str := IntToStr(num);
  for I := 1 to len - Length(Str) do
    Result := Result + fill;
  Result := Result + Str;
end;

function IsInB(Src: string; Pos: Integer; targ: string): Boolean;
var
  tLen, I           : Integer;
begin
  Result := False;
  tLen := Length(targ);
  if Length(Src) < Pos + tLen then
    exit;
  for I := 0 to tLen - 1 do
    if UpCase(Src[Pos + I]) <> UpCase(targ[I + 1]) then
      exit;

  Result := True;
end;

function IsInRect(X, Y: Integer; Rect: TRect): Boolean;
begin
  if (X >= Rect.Left) and (X <= Rect.Right) and (Y >= Rect.Top) and (Y <=
    Rect.Bottom) then

⌨️ 快捷键说明

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