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

📄 ottlibs.pas

📁 OttLib套件使用说明: 1、OttEnter控件:该控件主要实现在窗口中按回车键跳转到下一控件的功能;该控件是非可视控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
   State[3] := $10325476;
   Count[0] := 0;
   Count[1] := 0;
   ZeroMemory(@Buffer, SizeOf(MD5Buffer));
 end;
end;

// Update given Context to include Length bytes of Input
procedure MD5Update(var Context: MD5Context; Input: pChar; Length: longword);
var
 Index: longword;
 PartLen: longword;
 I: longword;
begin
 with Context do begin
   Index := (Count[0] shr 3) and $3f;
   inc(Count[0], Length shl 3);
   if Count[0] < (Length shl 3) then inc(Count[1]);
   inc(Count[1], Length shr 29);
 end;
 PartLen := 64 - Index;
 if Length >= PartLen then begin
   CopyMemory(@Context.Buffer[Index], Input, PartLen);
   Transform(@Context.Buffer, Context.State);
   I := PartLen;
   while I + 63 < Length do begin
     Transform(@Input[I], Context.State);
     inc(I, 64);
   end;
   Index := 0;
 end else I := 0;
 CopyMemory(@Context.Buffer[Index], @Input[I], Length - I);
end;

// Finalize given Context, create Digest and zeroize Context
procedure MD5Final(var Context: MD5Context; var Digest: MD5Digest);
var
 Bits: MD5CBits;
 Index: longword;
 PadLen: longword;
begin
 Decode(@Context.Count, @Bits, 2);
 Index := (Context.Count[0] shr 3) and $3f;
 if Index < 56 then PadLen := 56 - Index else PadLen := 120 - Index;
 MD5Update(Context, @PADDING, PadLen);
 MD5Update(Context, @Bits, 8);
 Decode(@Context.State, @Digest, 4);
 ZeroMemory(@Context, SizeOf(MD5Context));
end;

// -----------------------------------------------------------------------------------------------

// Create digest of given Message
function MD5String(M: string): MD5Digest;
var
 Context: MD5Context;
begin
 MD5Init(Context);
 MD5Update(Context, pChar(M), length(M));
 MD5Final(Context, Result);
end;

// Create digest of file with given Name
function MD5File(N: string): MD5Digest;
var
 FileHandle: THandle;
 MapHandle: THandle;
 ViewPointer: pointer;
 Context: MD5Context;
begin
 MD5Init(Context);
 FileHandle := CreateFile(pChar(N), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
   nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
 if FileHandle <> INVALID_HANDLE_VALUE then try
   MapHandle := CreateFileMapping(FileHandle, nil, PAGE_READONLY, 0, 0, nil);
   if MapHandle <> 0 then try
     ViewPointer := MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0);
     if ViewPointer <> nil then try
       MD5Update(Context, ViewPointer, GetFileSize(FileHandle, nil));
     finally
       UnmapViewOfFile(ViewPointer);
     end;
   finally
     CloseHandle(MapHandle);
   end;
 finally
   CloseHandle(FileHandle);
 end;
 MD5Final(Context, Result);
end;

// Create hex representation of given Digest
function MD5Print(D: MD5Digest): string;
var
 I: byte;
const
 Digits: array[0..15] of char =
   ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
begin
 Result := '';
 for I := 0 to 15 do Result := Result + Digits[(D[I] shr 4) and $0f] + Digits[D[I] and $0f];
end;

// -----------------------------------------------------------------------------------------------

// Compare two Digests
function MD5Match(D1, D2: MD5Digest): boolean;
var
 I: byte;
begin
 I := 0;
 Result := TRUE;
 while Result and (I < 16) do begin
   Result := D1[I] = D2[I];
   inc(I);
 end;
end;

{ TottEnter }

constructor TottEnter.Create(AOwner: TComponent);
var i: integer;
begin
  if AOwner is TCustomForm then
  begin
    for i:= 0 to AOwner.ComponentCount-1 do
    begin
      if AOwner.Components[i] is TottEnter then
      begin
        raise Exception.Create('该窗体上已经有该类型控件');
      end;
    end;
  end
  else
    raise Exception.Create('该控件只能放于窗体上');
    
  inherited;
  FVersion := 'OttLib 1.0';
  if not (csDesigning in ComponentState) then
  begin
    FOldWindowProc := TCustomForm(AOwner).WindowProc;
    TCustomForm(AOwner).WindowProc := NewWindowProc;
  end;
end;

destructor TottEnter.Destroy;
begin
  if Assigned(Owner) then
  if not (csDesigning in ComponentState) then
  if Assigned(FOldWindowProc) then
  begin
      TCustomForm(Owner).WindowProc := FOldWindowProc;
      FOldWindowProc := nil;
  end;
  inherited;
end;

function TottEnter.EncrypString(str, Key: String): string;
var KeyLen, KeyPos, OffSet, SrcPos, SrcAsc: Integer;
  Dest: String;
begin
  KeyLen := Length(Key);
  if KeyLen  = 0 then
    Key := FVersion;
  KeyPos := 0;
  Randomize();
  OffSet := Random(256);
  Dest := Format('%1.2x', [OffSet]);
  for SrcPos := 1 to Length(str) do
  begin
    SrcAsc := (Ord(Str[SrcPos]) + OffSet) MOD 255;
    if KeyPos < KeyLen then
      KeyPos := KeyPos + 1
    else
      KeyPos := 1;
    SrcAsc := SrcAsc xor Ord(Key[KeyPos]);
    Dest := Dest + Format('%1.2x', [SrcAsc]);
    OffSet := SrcAsc;
  end;
  Result := Dest;
end;

procedure TottEnter.NewWindowProc(var Msg: TMessage);
begin
  if Msg.Msg in [$000C, $000D, $000E] then
  begin
    if Encrypt then
    begin
      Msg.Msg := 0;
      exit;
    end;
  end;
  FOldWindowProc(Msg);
  if FEnable then   
  begin
    if not ((csDesigning in Owner.ComponentState) or (csDestroying in Owner.ComponentState)) then
    begin
      if TCustomForm(Owner).Active then
      if Assigned(TCustomForm(Owner).ActiveControl) then
      if TCustomForm(Owner).ActiveControl.Tag <> -1 then
      if Msg.WParam = VK_RETURN then
      begin
        if IsPublishedProp(TCustomForm(Owner).ActiveControl, 'Version') then
          if TypInfo.GetStrProp(TCustomForm(Owner).ActiveControl, 'Version') = FVersion then
            exit;
            
        Msg.WParam := VK_TAB;
        FOldWindowProc(Msg);
        if TCustomForm(Owner).ActiveControl is TCustomGrid then
        begin
          SendMessage(TCustomForm(Owner).ActiveControl.Handle, WM_KEYDOWN, VK_TAB, 0);
        end;
      end;
    end;
  end;
end;

procedure TottEnter.SetEnable(Value: Boolean);
begin
  FEnable := Value;
end;

function TottEnter.DecrypString(str, Key: String): string;
var KeyLen, KeyPos, OffSet, SrcPos, SrcAsc, TmpSrcAsc: Integer;
  dest: string;
begin
  Result := '';
  KeyLen := Length(Key);
  if KeyLen = 0 then
    Key := FVersion;
  KeyPos := 0;
//  TmpSrcAsc := 0;
  try
    if Length(str)<2 then
      exit;
    OffSet := StrToInt('$'+Copy(str, 1, 2));
    SrcPos := 3;
    if SrcPos >= Length(str) then
    begin
      exit;
    end;
    repeat
      SrcAsc := StrToInt('$'+Copy(str, SrcPos, 2));
      if KeyPos < KeyLen then
        KeyPos := KeyPos + 1
      else
        KeyPos := 1;
      TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
      if TmpSrcAsc <= OffSet then
        TmpSrcAsc := 255 + TmpSrcAsc - OffSet
      else
        TmpSrcAsc := TmpSrcAsc - OffSet;
      dest := dest + Chr(TmpSrcAsc);
      OffSet := SrcAsc;
      SrcPos := SrcPos + 2;
    until SrcPos >= Length(str);
    Result := Dest;
  except
    Result := '';
  end;
end;

function TottEnter.MD5_File(const str: String): string;
begin
  Result := MD5Print(MD5File(str));
end;

function TottEnter.MD5_String(const str: String): String;
begin
  Result := MD5Print(MD5String(str));
end;

function TottEnter.MD5_Match(const str1, str2: string): Boolean;
begin
  Result := MD5Match(MD5File(str1), MD5File(str2));
end;

end.

//OttLib end

⌨️ 快捷键说明

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