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

📄 mypublic.pas

📁 在SQLSERVER数据库查找任一表中的任意数据
💻 PAS
字号:
unit MyPublic;

interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  IniFiles, ShellApi, StdCtrls, Registry, WinSock, Bleeper, Db,
  BleepInt, Clipbrd, extctrls,comctrls, buttons, Variants ;

{函数声明区}

  Function GetAppVer(AppFileName:string):String;//得到应用程序版本号

  Function EnCode(Const S:String):String ;  //加密字符串
  Function DeCode(Const S:String):String ;  //解密字符串

  Function GetIpAddress:String ;  //获取本机IP地址
  Function GetComputerName:String ;  //获取本机名称

implementation


const
    Base64: string = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz~#%&*+-';
    UnBase64: array[0..255] of byte =
       (128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128, //0-15
        128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //16-31
        128,128,128, 58,128, 59, 60,128, 128,128, 61, 62,128, 63,128,128,  //32-47
        128,128,  0,  1,  2,  3,  4,  5,   6,  7,128,128,128,128,128,128,  //48-63
        128,  8,  9, 10, 11, 12, 13, 14,  15,128, 16, 17, 18, 19, 20,128,  //64-79
         21, 22, 23, 24, 25, 26, 27, 28,  29, 30, 31,128,128,128,128,128,  //80-95
        128, 32, 33, 34, 35, 36, 37, 38,  39, 40, 41, 42,128, 43, 44, 45,  //96-111
	 46, 47, 48, 49, 50, 51, 52, 53,  54, 55, 56,128,128,128, 57,128,  //112-127
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //128-143
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //144-159
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //160-175
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //176-191
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //192-207
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //208-223
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128,  //224-239
	128,128,128,128,128,128,128,128, 128,128,128,128,128,128,128,128);  //240-255


Function GetAppVer(AppFileName:string):String;//得到应用程序版本号
var
   myHandle,Size:DWORD;
   RezBuffer:String;
   FileInfoBuffer:PVSFixedFileInfo;
   FileName:String;
begin
   Result:='';
   FileName:=AppFileName;
   Size:=GetFileVersionInfoSize(PChar(FIleName),myHandle);
   if Size<=0 then Exit;
   SetLength(RezBuffer,Size);
   if  not GetFileVersionInfo(PChar(FIleName),myhandle,Size,PChar(RezBuffer)) then Exit;
   if not VerQueryValue(Pchar(RezBuffer),'\',pointer(FileInfoBuffer),Size) then Exit;
   if Size<SizeOf(TVSFixedFileInfo) then Exit;
    with  FileInfoBuffer^ do
        Result:=Format('%d.%d.%d.%d',[HIWORD(dwFileVersionMS),LOWORD(dwFileVersionMS),
                                      HIWORD(dwFileVersionLS),LOWORD(dwFileVersionLS)]);
end;

Function EnCode(Const S:String):String ;  //加密字符串
var
  s4: string;
  i, j, k: integer;
  b: byte;
begin
  Result := '';
  SetLength(s4, 4);
  b := 0;
  i := 1;
  j := 2;
  k := 2;
  while i <= length(s) do begin
    b := b or ((ord(s[i]) and $C0) shr k);
    inc(k,2);
    s4[j] := Base64[(ord(s[i]) and $3F)+1];
    inc(i);
    inc(j);
    if j > 4 then begin
      s4[1] := Base64[b+1];
      b := 0;
      j := 2;
      k := 2;
      Result := Result + s4;
    end;
  end;
  if j <> 2 then begin // Flush data in s4.
    s4[j] := '.';
    s4[1] := Base64[b+1];
    Result := Result + s4;
    SetLength(Result, Length(Result) - (4 - j));
  end else
    Result := Result + '.';
end;


Function DeCode(Const S:String):String ;  //解密字符串
var
  i, j, k: integer;
  b: byte;
begin
  Result := '';
  b := 0;
  i := 1;
  j := 0;
  k :=0;
  while (i <= length(s)) and (s[i] <> '.') do begin
    if j = 0 then begin
      b := UnBase64[ord(s[i])];
      k := 2;
    end else begin
      Result := Result + chr(UnBase64[ord(s[i])] or ((b shl k) and $C0));
      inc(k,2);
    end;
    inc(j);
    j := j and 3;
    inc(i);
  end;
end;

Function GetIpAddress:String ;  //获取本机IP地址
Var
  Ip:String;
  Ipstr:String;
  ch:ARRAY[1..32] of CHAR ;
  i:integer;
  WSData:TWsAData;
  MyHost:PHostEnt;
Begin
  If WSAstartup(2,wsdata)<>0 Then Begin
    Result := '';
    Exit ;
  End;
  Try
    If GetHostName(@ch[1],32)<>0 Then Begin
      Result := '';
      Exit ;
    End;
  Except
    Result:= '' ;
    Exit ;
  End;
  MyHost:=GetHostByName(@ch[1]);
  If MyHost=Nil Then Begin
    Result := '' ;  //IP地址为空
    Exit ;
  End Else Begin
    For i:=1 to 4 Do Begin
      Ip:=Inttostr(Ord(MyHost.h_addr^[i-1]));
      ipStr:=Ipstr+Ip;
      If i<4 Then IpStr:=IpStr+'.' ;
    End;
    Result:=Ipstr ;
  End;
End;

Function GetComputerName:String ;  //获取本机名称
Var
  ch:ARRAY[1..32] of CHAR ;
  WSData:TWsAData;
  MyHost:PHostEnt;
Begin
  If WSAstartup(2,wsdata)<>0 Then Begin
    Result := '';
    Exit ;
  End;
  Try
    If GetHostName(@ch[1],32)<>0 Then Begin
      Result := '';
      Exit ;
    End;
  Except
    Result:= '' ;
    Exit ;
  End;
  MyHost:=GetHostByName(@ch[1]);
  If MyHost=Nil Then
    Result := '' //IP地址为空
  Else Result := MyHost.h_name;
End;

end.

⌨️ 快捷键说明

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