?? genfunc.pas
字號:
unit genFunc;
//{$DEFINE ISBASEACCESS}
//{$DEFINE ISDEMO}
{$DEFINE ISHASDOG}
//{$DEFINE ISMEPG4}
interface
uses DB, ADODB, Windows, Controls, Variants, Classes;
type
TUserInfo = record
SkinPath: string;
ExePath: string;
OutDate: TDate;
IsDemo: Boolean; //2006-3-30 11:24:21 nicholas 說明:是否Demo。
LoginTime: TDateTime; //2006-3-30 11:30:50 nicholas 說明:登錄時(shí)間。
IsHasDog: Boolean;
IsBaseAccess: Boolean;
ServerName: string;
DataName: string;
Password: string;
FieldName: string; //2006-4-6 15:55:21 nicholas 說明:排行點(diǎn)數(shù)增加每天的點(diǎn)數(shù),統(tǒng)計(jì)一個(gè)月的排行.
PreFieldName: string; //2006-4-6 16:18:27 nicholas 說明:排行點(diǎn)數(shù)增加前一天的點(diǎn)數(shù),統(tǒng)計(jì)一個(gè)月的排行.
KTVDataName: string;
end;
TSendSongRec = record
SongNum: string[16];
SongName: string[32];
end;
function SetAdoQue(AdoQue: TADOQuery; sSQL: string; bSel: boolean = true): boolean;
function DiskVolume(Drive: string): string;
function GetPureFileName(sFileName: string): string;
function GetGBCode(sStr: string): string;
function GetGBCodeA(sStr: string): string;
function GetWordCount(sStr: string): Integer;
function GetFileSizeByFileStream(const FileName: string): int64;
function GetPcName: string;
function GetIP: string;
function BIG5ToGB(BIG5Str: string): Ansistring;
function GBToBIG5(GBStr: string): Ansistring;
function AnsiToUnicode(Ansi: string): string;
function ReadHex(AString: string): integer;
function UnicodeToAnsi(Unicode: string): string;
function UnicodeEncode(Str: string; CodePage: integer): WideString;
function UnicodeDecode(Str: WideString; CodePage: integer): string;
function Gb2Big5(Str: string): string;
function Gb2Big5A(Str: string): string;
function Big52Gb(Str: string): string;
function Big52GbA(Str: string): string;
function GBUnicodeToBig5Unicode(Str:string):string;
function Big5UnicodeToGBUnicode(Str:string):string;
function GBStrToBig5Unicode(Str:string):string;
function EncryptStr(const s: string; skey: string): string;
function GetNetCardSN: string;
function myStrtoHex(s: string): string; //原字符串轉(zhuǎn)16進(jìn)制字符串
var
genInfo: TUserInfo;
implementation
uses SysUtils, Winsock, Nb30;
function SetAdoQue(AdoQue: TADOQuery; sSQL: string; bSel: boolean = true): boolean;
//設(shè)定ADOQuery結(jié)果集
begin
Result := true;
try
AdoQue.Close;
AdoQue.SQL.Clear;
AdoQue.SQL.Add(sSQL);
if bSel then
begin
AdoQue.open;
if AdoQue.RecordCount = 0 then
begin
Result := false;
exit;
end
end
else AdoQue.ExecSQL;
except
Result := false;
exit;
end;
end;
function DiskVolume(Drive: string): string;
var
FSFlags, MaxLength: DWORD;
VolName, Path: string;
DriveStr: string;
begin
Result := '';
Drive := UpperCase(Drive);
if not (Drive[1] in ['C'..'Z']) then
begin
Exit;
end;
SetLength(VolName, 64);
if Pos(':', Drive) > 0 then
begin
DriveStr := ExtractFileDrive(Drive) + '\';
end
else
begin
DriveStr := Copy(Drive, 1, 1) + ':\';
end;
GetVolumeInformation(PChar(DriveStr), PChar(VolName), Length(VolName), nil, MaxLength, FSFlags, nil, 0);
Result := VolName;
end;
function GetPureFileName(sFileName: string): string;
var
sTemp, sExt: string;
begin
sTemp := ExtractFileName(sFileName);
sExt := ExtractFileExt(sTemp);
sTemp := Copy(sTemp, 1, Length(sTemp) - Length(sExt));
Result := sTemp;
end;
function GetGBCode(sStr: string): string;
var
i, o: Integer;
sTemp: string;
begin
sTemp := '';
for i := 1 to Length(sStr) do
begin
o := Ord(sStr[i]);
sTemp := sTemp + IntToHex(o, 2);
end;
Result := sTemp;
end;
function GetGBCodeA(sStr: string): string;
var
i, o: Integer;
sTemp: string;
begin
sTemp := '';
for i := 1 to Length(sStr) do
begin
o := Ord(sStr[i]);
sTemp := sTemp + IntToHex(o, 2) + ' ';
end;
Result := sTemp;
end;
function GetWordCount(sStr: string): Integer;
var
nLen: Integer;
i: Integer;
iCount: Integer;
begin
nLen := Length(sStr);
i := 1;
iCount := 0;
while i <= nLen do
begin
if Ord(sStr[i]) = 32 then
begin
Inc(i);
//Inc(iCount);
Continue;
end;
if (Ord(sStr[i]) >= 33) and (Ord(sStr[i]) <= 126) then
begin
while (i + 1) <= nLen do
begin
if (Ord(sStr[i + 1]) >= 33) and (Ord(sStr[i + 1]) <= 126) then
begin
Inc(i);
end
else
begin
Break;
end;
end;
if Ord(sStr[i]) <> 32 then
begin
Inc(iCount);
Inc(i);
end;
end
else
begin
Inc(iCount);
i := i + 2;
end;
end;
Result := iCount;
end;
function GetFileSizeByFileStream(const FileName: string): int64;
var
FileStream: TFileStream;
begin
Result := 0;
if FileExists(FileName) = False then
begin
Exit;
end;
FileStream := TFileStream.Create(FileName, fmOpenRead, fmShareDenyNone);
try
Result := FileStream.Size;
finally
FileStream.Free;
end;
end;
function GetIP: string;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPinAddr;
Buffer: array[0..63] of char;
I: integer;
GInitData: TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '127.0.0.1';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(Buffer);
if phe = nil then Exit;
pptr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
Result := StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
function GetPcName: string;
var
PCName: PChar;
Size: Dword;
begin
GetMem(PCName, 255);
Size := 255;
GetComputerName(PCName, size);
Result := PcName;
FreeMem(PCName); //得到計(jì)算機(jī)名
end;
function BIG5ToGB(BIG5Str: string): Ansistring;
var
Len: Integer;
pBIG5Char: PChar;
pGBCHSChar: PChar;
pGBCHTChar: PChar;
pUniCodeChar: PWideChar;
begin
pBIG5Char := PChar(BIG5Str);
Len := MultiByteToWideChar(950, 0, pBIG5Char, -1, nil, 0);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//Big5 -> UniCode*&(-
MultiByteToWideChar(950, 0, pBIG5Char, -1, pUniCodeChar, Len);
Len := WideCharToMultiByte(936, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pGBCHTChar, Len * 2);
GetMem(pGBCHSChar, Len * 2);
ZeroMemory(pGBCHTChar, Len * 2);
ZeroMemory(pGBCHSChar, Len * 2);
//UniCode->GB CHTC h/^
WideCharToMultiByte(936, 0, pUniCodeChar, -1, pGBCHTChar, Len, nil, nil);
//GB CHT -> GB CHS4qR
LCMapString($804, LCMAP_SIMPLIFIED_CHINESE, pGBCHTChar, -1, pGBCHSChar, Len);
Result := string(pGBCHSChar);
FreeMem(pGBCHTChar);
FreeMem(pGBCHSChar);
FreeMem(pUniCodeChar);
end;
function GBToBIG5(GBStr: string): Ansistring;
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936, 0, pGBCHSChar, -1, nil, 0);
GetMem(pGBCHTChar, Len * 2 + 1);
ZeroMemory(pGBCHTChar, Len * 2 + 1);
//GB CHS -> GB CHTmzna
LCMapString($804, LCMAP_TRADITIONAL_CHINESE, pGBCHSChar, -1, pGBCHTChar, Len * 2);
GetMem(pUniCodeChar, Len * 2);
ZeroMemory(pUniCodeChar, Len * 2);
//GB CHT -> UniCodebPb\p0
MultiByteToWideChar(936, 0, pGBCHTChar, -1, pUniCodeChar, Len * 2);
Len := WideCharToMultiByte(950, 0, pUniCodeChar, -1, nil, 0, nil, nil);
GetMem(pBIG5Char, Len);
ZeroMemory(pBIG5Char, Len);
//UniCode -> Big5 {J$
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -