Delphi常用函数库

unit SkyPublic;
 
interface
 
uses
  Windows,SysUtils,Classes,Controls,Dialogs,ShellApi,Menus,StdCtrls,
  registry,Forms,Graphics,Math,DateUtils;
 
type
  TQuarter = 1..4;
 
  TChinaNumFormat = (cnfBig,cnfSmall,cnfArab);
 
  TChinaBigFormat = (cbfFull,cbfBlank);
 
  TNumChar='0'..'9';
 
  TStringArray = array of string;
 
  TCharSet = set of Char;
 
  TFontRecord = record
    CharSet:Byte;
    Color:Integer;
    Name:string;
    Size:Integer;
    Style:Byte;
    PixelsPerInch:Integer;
    Pitch:0..2;
    Height:Integer;
  end;
 
const
  CR = #13;
  LF = #10;
  NumCharSet=['0'..'9'];
  NameCharSet = ['A'..'Z','a'..'z','0'..'9','_'];
 
var
  MimaFileName:string;
  PositionMima:array [0..2] of Integer = (91,92,93);
 
{*****************************类操作******************************}
{显示类及其继承信息函数}
function ShowClassName(Obj:TObject):string;
procedure GetClassInfos(Obj:TComponent;StrList:TStringList);
procedure SaveClassInfos(Obj:TComponent;FileName:string);
 
{*****************************文件操作******************************}
{建文件夹}
function CreateDirs(APath:string):Boolean;
{拷贝}
function FileCopy(From, Dest: string;S:Integer=0;Dialog:Boolean=True):Boolean;
{移动}
procedure FileMove(From, Dest: string);
{删除}
procedure FileDelete(ADirName: string);
{更名}
function FileRename(From, Dest: string):Boolean;
 
{***************************控件操作********************************}
{TStrings,在Combobox中添加或者删除一个字符串}
procedure StringsOperation(ComboBox:TComboBox;IsAdd:Boolean;No:string='');
 
{***************************日期操作********************************}
{返回头尾日期}
procedure GetHeadTailDate(const SelfDate:TDate;var HeadDate,TailDate:TDate);overload;
procedure GetHeadTailDate(const Year,Month:Integer;var HeadDate,TailDate:TDate);overload;
{返回一月有多少天}
function ReturnHowDay(const AYear,AMonth:word):Word;
{返回季度头尾日期}
procedure GetQuarter(AYear:Word;AQuarter:TQuarter;var HeadDate,TailDate:TDate);overload;
procedure GetQuarter(SelfDate:TDate;var HeadDate,TailDate:TDate);overload;
procedure GetAccYearMonth(ADate:TDateTime;var Y,M:Word);
 
{**************************字符串操作*******************************}
{**************************string Function*******************************}
{得到1个字符在字符串中的个数}
function GetCharNum(const Ch:Char; const Str: string):Integer;
{Ini字符串和String字符串互相转换}
function IniStrToStr(const Str: string): string;
function StrToIniStr(const Str: string): string;
{给字符串加一个'\'}
function AddBackSlash(const S: string): string;
{减少字符串的长度}
procedure DecStrLen(var S: string; DecBy: Integer);
{返回有回车换行的字符串Position位置所在的字符串}
function GetCurLine(const S: string; Position: Integer): string;
{返回给定字符串的内存分配大小}
function GetStrAllocSize(const S: string): Longint;
{ 得到字符串的基准数 }
function GetStrRefCount(const S: string): Longint;
{清除A中指定的字符}
function KillChars(const S: string; A: array of Char; CaseSensitive: Boolean):string;
{ 返回子字符串在字符串中最后一个位置 }
function LastPos(const SubStr, S: string): Integer;
{ 设置字符串的实际长度 }
procedure RealizeLength(var S: string);
{ 移去字符串末尾的'\'}
function RemoveBackSlash(const S: string): string;
{移去字符串空格}
function RemoveSpaces(const S: string): string;
{字符串取反}
function ReverseStr(const S: string): string;
{除去前后回车}
function TrimEnterLeft(S:string):string;
function TrimEnterRight(S:string):string;
function TrimEnter(S:string):string;
{******************************PChar Function***************************}
procedure StrGetCurLine(StartPos, CurPos: PChar; TotalLen: integer;
  var LineStart: PChar; var LineLen: integer);
{ 返回最后一个指定字符串及其以后的字符 }
function StrLastPos(Str1, Str2: PChar): PChar;
{截取第一个指定字符串及其以后的字符,大小写不敏感}
function StrIPos(Str1, Str2: PChar): PChar;
{截取第一个指定字符及其以后的字符,大小写不敏感}
function StrIScan(Str: PChar; Chr: Char): PChar;
{ 字符串取反 }
procedure StrReverse(P: PChar);
 
{返回中文大写数字}
function GetChinaNum(Num:TNumChar;ChinaNumFormat:TChinaNumFormat=cnfBig):string;
{将数字变成中文大写}
function FloatToChinaBig(Num:Double;ChinaBigFormat:TChinaBigFormat=cbfFull;Blanks:Byte=0):string;
function FloatToChnStr(Value: Real; ClearZero: Boolean; full:Boolean=False): String;
{将数字变成英文}
function FloatToEnglish(Num:Double):string;
{日期用英文}
function DateToEng(ADate:TDate;th:Boolean=False):string;
{取得SQL日期字符串等}
function DateToSQLDateStr(ADate:TDateTime):string;
function StrToSQLDateStr(Str:string):string;
function TimeToSQLTimeStr(ATime:TDateTime):string;
function StrToSQLTimeStr(Str:string):string;
function DateTimeToSQLDateTimeStr(ADateTime:TDateTime):string;
function StrToSQLDateTimeStr(Str:string):string;
{返回有逗号的金额字符串}
function FloatToMoneyStr(Num:Double;const HasSymbol:Boolean=False):string;
{Bool与字符串的转换}
function StrToBool(const Str:string):Boolean;
function BoolToStr(const Bool:Boolean):string;
{判断是否日期等}
function IsDate(const CheckString:string):Boolean;
function IsDateTime(const CheckString:string):Boolean;
function IsTime(const CheckString:string):Boolean;
function IsInteger(const CheckString:string):Boolean;
function IsFloat(const CheckString:string):Boolean;
{多字符串ShowMessage}
procedure ShowMessages(const Strings:array of string);
{新名称}
function NameToNewName(const Str:string):string;
{FloatTo%百分比}
function FloatToRate(Num:Double;Pos:Word):string;
{字体存贮}
procedure FontRecordToFont(FontRecord:TFontRecord;Font:TFont);
function FontToFontRecord(Font:TFont):TFontRecord;
function FontStylesToInt(FontStyles:TFontStyles):Byte;
function IntToFontStyles(FontInteger:Byte):TFontStyles;
 
{****************************数学*********************************}
{n次方}
function Power(X,Y:Extended):Extended;
{N的阶层}
function Order(N: Word): Extended;//(用Pascal写的N的阶层)
{得到小数点位数}
function GetFloatPointNum(Fl:Double):Integer;
{小数点位数,四舍五入法}
function FloatToNewFloat(AValue:Double):Double;
function FloatToNewFloatN(AValue:Double;N:Word=4):Double;
 
{******************************系统操作*******************************}
{关闭计算机}
function WinExit (iFlags: integer) : Boolean;
{防止开启多个应用程序}
procedure PreventMany(Name:string);
{得到应用程序的路径}
function GetApplicationDir(AppName:string):string;
{加到启动}
function RegAddToRun(Name,Value:string):Boolean;
procedure DeleteOneItem(Name:string);
{得到Delphi路径}
function GetDelphiDir:string;
{得到系统路径}
function GetSystemDir:string;
{得到windows路径}
function GetWindowsDir:string;
{得到计算机名}
function GetComputerNameD:string;
{设置计算机名}
function SetComputerNameD(Name:string):Boolean;
{执行一个文件}
function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
 
implementation
 
{显示类及其继承信息函数}
function ShowClassName(Obj:TObject):string;
var
  Str:string;
  K:TClass;
begin
  K:=Obj.ClassType;
  while not K.ClassNameIs('TObject') do
  begin
    Str:=K.ClassParent.ClassName+'——>'+Str;
    K:=K.ClassParent;
  end;
  Result:=Str+Obj.ClassName;
end;
 
procedure GetClassInfos(Obj:TComponent;StrList:TStringList);
var
  i:Integer;
  S:string;
begin
  StrList.Clear;
  for I:=0 to Obj.ComponentCount-1 do
  begin
    S:='类名:'+Obj.Components.ClassName+' '+'名称:'+Obj.Components.Name;
    StrList.Add(S);
  end;
end;
 
procedure SaveClassInfos(Obj:TComponent;FileName:string);
var
  i:Integer;
  S:string;
  StrList:TStringList;
begin
  StrList:=TStringList.Create;
  try
    for I:=0 to Obj.ComponentCount-1 do
    begin
      S:='类名:'+Obj.Components.ClassName+' '+'名称:'+Obj.Components.Name;
      StrList.Add(S);
    end;
    StrList.SaveToFile(FileName);
  finally
    StrList.Free;
  end;
end;
 
{建文件夹}
function  CreateDirs(APath:string):Boolean;
var
  CurrentPath:string;
  UsePath:string;
begin
  CurrentPath:=GetCurrentDir;
  UsePath:=Trim(APath);
  if Pos('\',UsePath)=1 then
  begin
    UsePath:=Copy(CurrentPath,1,2)+UsePath;
  end
  else if Pos(':',UsePath)<>2 then UsePath:=CurrentPath+'\'+UsePath;
  Result:=ForceDirectories(UsePath);
end;
 
{拷贝}{0:如果有同文件名则改名。1:如果同文件名则覆盖。}
function FileCopy(From, Dest: string;S:Integer=0;Dialog:Boolean=True):Boolean;
var
  T: TSHFileOpStruct;
  FromDir:PChar;
  ToDir:PChar;
begin
  GetMem(FromDir,Length(From)+2);
  try
    GetMem(ToDir,Length(Dest)+2);
    try
      FillChar(FromDir^,Length(From)+2,0);
      FillChar(ToDir^,Length(Dest)+2,0);
 
      StrCopy(FromDir,PChar(From));
      StrCopy(ToDir,PChar(Dest));
 
      with T do
      begin
        Wnd    :=0;
        wFunc  :=FO_COPY;
        pFrom  :=FromDir;
        pTo    :=ToDir;
        if S=0 then
          fFlags :=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION
        else fFlags :=FOF_NOCONFIRMATION;
        if not Dialog then
          fFlags:=fFlags or FOF_SILENT;
        fAnyOperationsAborted:=False;
        hNameMappings:=nil;
        lpszProgressTitle:=nil;
        if SHFileOperation(T)=0 then
          Result:=True
        else Result:=False;
      end;
    finally
      FreeMem(ToDir,Length(Dest)+2);
    end;
  finally
    FreeMem(FromDir,Length(From)+2);
  end;
end;
 
{移动}
procedure FileMove(From, Dest: string);
var
  T: TSHFileOpStruct;
  FromDir:PChar;
  ToDir:PChar;
begin
  GetMem(FromDir,Length(From)+2);
  try
    GetMem(ToDir,Length(Dest)+2);
    try
      FillChar(FromDir^,Length(From)+2,0);
      FillChar(ToDir^,Length(Dest)+2,0);
 
      StrCopy(FromDir,PChar(From));
      StrCopy(ToDir,PChar(Dest));
 
      with T do
      begin
        Wnd    :=0;
        wFunc  :=FO_MOVE;
        pFrom  :=FromDir;
        pTo    :=ToDir;
        fFlags :=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
        fAnyOperationsAborted:=False;
        hNameMappings:=nil;
        lpszProgressTitle:=nil;
        if SHFileOperation(T)<>0 then
          raise Exception.Create('移动文件操作不成功!');
      end;
    finally
      FreeMem(ToDir,Length(Dest)+2);
    end;
  finally
    FreeMem(FromDir,Length(From)+2);
  end;
end;
 
{删除}
procedure FileDelete(ADirName: string);
var
  SHFileOpStruct:TSHFileOpStruct;
  DirName:PChar;
begin
  Getmem(DirName,Length(ADirName)+2);
  try
    FillChar(Dirname^,Length(ADirName)+2,0);
    StrCopy(DirName,PChar(ADirName));
 
    with SHFileOpStruct do
    begin
      Wnd:=0;
      wFunc:=FO_DELETE;
      pFrom:=DirName;
      pTo:=nil;
      fFlags :=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
 
      fAnyOperationsAborted:=False;
      hNameMappings:=nil;
      lpszProgressTitle:=nil;
    end;
 
    if SHfileOperation(SHFileOpStruct)<>0 then
      raise Exception.Create('删除文件操作不成功!');
  finally
    FreeMem(DirName,Length(ADirName)+2);
  end;
end;
 
{更名}
function FileRename(From, Dest: string):Boolean;
//var
//  T: TSHFileOpStruct;
//  FromDir:PChar;
//  ToDir:PChar;
//  FromDirectory,DestDirectory:string;
begin
  Dest:=ExtractFileName(Dest);
  Result:=RenameFile(From,Dest);
end;
 
{得到应用程序的路径}
function GetApplicationDir(AppName:string):string;
var
  AppPath:string;
  reg:TRegistry;
  Name:string;
  ExtName:string;
begin
  ExtName:=Copy(AppName,Length(AppName)-3,4);
  if ExtName[1]<>'.' then AppName:=AppName+'.exe';
  Name:='Software\Microsoft\Windows\CurrentVersion\App Paths\'+AppName;
  reg:=TRegistry.Create;
  try
    reg.RootKey:=HKEY_LOCAL_MACHINE;
    reg.OpenKey(Name,False);
    AppPath:=reg.ReadString('path');
    AppPath:=AddBackSlash(AppPath);
    reg.CloseKey;
  finally
    reg.Free;
  end;
  Result:=AppPath;
end;
 
{加到启动}
function RegAddToRun(Name,Value:string):Boolean;
var
  Reg:TRegistry;
  Values:string;
begin
  Result:=False;
  Reg:=TRegistry.Create;
  try
    Reg.RootKey:=HKEY_LOCAL_MACHINE;
    Reg.OpenKey('software\microsoft\windows\currentversion\run\',False);
    Values:=Reg.ReadString(Name);
    if Values<>Value then
    begin
      Reg.WriteString(Name,Value);
      Result:=True;
    end;
  finally
    Reg.Free;
  end;
end;
procedure DeleteOneItem(Name:string);
var
  Reg:TRegistry;
begin
  Reg:=TRegistry.Create;
  try
    Reg.RootKey:=HKEY_LOCAL_MACHINE;
    Reg.OpenKey('software\microsoft\windows\currentversion\run\',False);
    if Reg.ValueExists(Name) then
      Reg.DeleteValue(Name)
  finally
    Reg.Free;
  end;
end;
 
{得到delphi路径}
function GetDelphiDir:string;
begin
  Result:=GetApplicationDir('Delphi32.exe');
end;
 
{得到系统路径}
function GetSystemDir:string;
var
  Buffer: array[0..MAX_PATH - 1] of Char;
begin
  SetString(Result, Buffer, GetSystemDirectory(Buffer,SizeOf(Buffer)));
end;
 
{得到windows路径}
function GetWindowsDir:string;
var
  Buffer: array[0..MAX_PATH - 1] of Char;
begin
  SetString(Result, Buffer, GetWindowsDirectory(Buffer,SizeOf(Buffer)));
end;
 
{得到计算机名}
function GetComputerNameD:string;
var
  Buffer: array[0..MAX_COMPUTERNAME_LENGTH] of Char;
  BSize:Cardinal;
begin
  BSize:=SizeOf(Buffer);
  if  GetComputerName(Buffer,BSize) then
  begin
    Result:=Buffer;
  end
  else Result:='';
end;
 
{设置计算机名}
function SetComputerNameD(Name:string):Boolean;
begin
  if Length(Name)>MAX_COMPUTERNAME_LENGTH then
  Name:=Copy(Name,1,MAX_COMPUTERNAME_LENGTH);
  Result:=False;
  if SetComputerName(PChar(Name)) then
    Result:=True;
end;
 
function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..120] of Char;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;
 
{返回头尾日期}
procedure GetHeadTailDate(const SelfDate:TDate;var HeadDate,TailDate:TDate);overload;
const
  AHeadDay=1;
var
  AYear,AMonth,ATailDay,ASelfDay:Word;
begin
  DecodeDate(SelfDate,AYear,AMonth,ASelfDay);
  ATailDay:=ReturnHowDay(AYear,AMonth);
  HeadDate:=EncodeDate(AYear,AMonth,AHeadDay);
  TailDate:=EncodeDate(AYear,AMonth,ATailDay);
end;
 
procedure GetHeadTailDate(const Year,Month:Integer;var HeadDate,TailDate:TDate);overload;
const
  HeadDay=1;
var
  TailDay:Word;
begin
  TailDay:=ReturnHowDay(Year,Month);
  HeadDate:=EncodeDate(Year,Month,HeadDay);
  TailDate:=EncodeDate(Year,Month,TailDay);
end;
 
{返回一月有多少天}
function ReturnHowDay(const AYear,AMonth:word):Word;
begin
  case AMonth of
    1,3,5,7,8,10,12:Result:=31;
    4,6,9,11:Result:=30;
    2:begin
      if IsLeapYear(AYear) then
        Result:=29
      else Result:=28;
    end;
    else Result:=0;
  end;
end;
 
{返回季度头尾日期}
procedure GetQuarter(AYear:Word;AQuarter:TQuarter;var HeadDate,TailDate:TDate);overload;
var
  AHeadDate,ATailDate:TDate;
  HeadMonth,TailMonth:Word;
begin
  HeadMonth:=1;
  TailMonth:=1;
  case AQuarter of
    1:begin
        HeadMonth:=1;
        TailMonth:=3;
    end;
    2:begin
        HeadMonth:=4;
        TailMonth:=6;
    end;
    3:begin
        HeadMonth:=7;
        TailMonth:=9;
    end;
    4:begin
        HeadMonth:=10;
        TailMonth:=12;
    end;
  end;
  GetHeadTailDate(AYear,HeadMonth,AHeadDate,ATailDate);
  HeadDate:=AHeadDate;
  GetHeadTailDate(AYear,TailMonth,AHeadDate,ATailDate);
  TailDate:=ATailDate;
end;
 
procedure GetQuarter(SelfDate:TDate;var HeadDate,TailDate:TDate);overload;
var
  AYear,AMonth,ADay:Word;
  AQuarter:TQuarter;
begin
  AQuarter:=1;
  DecodeDate(SelfDate,AYear,AMonth,ADay);
  case AMonth of
    1..3:AQuarter:=1;
    4..6:AQuarter:=2;
    7..9:AQuarter:=3;
    10..12:AQuarter:=4;
  end;
  GetQuarter(AYear,AQuarter,HeadDate,TailDate);
end;
 
procedure GetAccYearMonth(ADate:TDateTime;var Y,M:Word);
var
  D:Word;
begin
  DecodeDate(ADate,Y,M,D);
  if M=1 then
  begin
    Y:=Y-1;
    M:=12;
  end
  else begin
    M:=M-1;
  end;
end;
 
{  *** Pascal string functions *** }
function GetCharNum(const Ch:Char; const Str: string):Integer;
var
  S:PChar;
begin
  S:=PChar(Str);
  Result:=0;
  while S^<>#0 do
  begin
    if S^=Ch then
    Inc(Result);
    Inc(S);
  end;
end;
 
function IniStrToStr(const Str: string): string;
var
  Buffer: array[0..4095] of Char;
  B, S: PChar;
begin
  if Length(Str) > SizeOf(Buffer) then
    raise Exception.Create('String to read from an INI file');
  S := PChar(Str);
  B := Buffer;
  while S^ <> #0 do
    if (S[0] = '\') and (S[1] = 'n') then
    begin
  B^ := #13;
  Inc(B);
  B^ := #10;
  Inc(B);
  Inc(S);
  Inc(S);
    end
    else
    begin
  B^ := S^;
  Inc(B);
  Inc(S);
    end;
  B^ := #0;
  Result := Buffer;
end;
 
function StrToIniStr(const Str: string): string;
var
  Buffer: array[0..4095] of Char;
  B, S: PChar;
begin
  if Length(Str) > SizeOf(Buffer) then
    raise Exception.Create('String to large to save in INI file');
  S := PChar(Str);
  B := Buffer;
  while S^ <> #0 do
    case S^ of
      #13, #10:
        begin
          if (S^ = #13) and (S[1] = #10) then Inc(S)
          else if (S^ = #10) and (S[1] = #13) then Inc(S);
          B^ := '\';
          Inc(B);
          B^ := 'n';
          Inc(B);
          Inc(S);
        end;
    else
      B^ := S^;
      Inc(B);
      Inc(S);
    end;
  B^ := #0;
  Result := Buffer;
end;
 
function AddBackSlash(const S: string): string;
begin
  Result := S;
  if S<>'' then
  begin
    if Result[Length(Result)] <> '\' then  // if last char isn't a backslash...
      Result := Result + '\';              // make it so
  end;
end;
 
procedure DecStrLen(var S: string; DecBy: Integer);
begin
  SetLength(S, Length(S) - DecBy);       // decrement string length by DecBy
end;
 
function GetCurLine(const S: string; Position: Integer): string;
var
  ResP: PChar;
  ResLen: integer;
begin
  StrGetCurLine(PChar(S), PChar(Longint(S) + Position - 1), Length(S), ResP,
    ResLen);
  SetString(Result, ResP, ResLen);
end;
 
function GetStrAllocSize(const S: string): Longint;
var
  P: ^Longint;
begin
  P := Pointer(S);                        // pointer to string structure
  dec(P, 3);                              // 12-byte negative offset
  Result := P^ and not $80000000 shr 1;   // ignore bits 0 and 31
end;
 
function GetStrRefCount(const S: string): Longint;
var
  P: ^Longint;
begin
  P := Pointer(S);                        // pointer to string structure
  dec(P, 2);                              // 8-byte negative offset
  Result := P^;
end;
 
function KillChars(const S: string; A: array of Char; CaseSensitive: Boolean):
  string;
var
  CharSet: TCharSet;
  i, count: integer;
begin
  CharSet := [];                         // empty character set
  for i := Low(A) to High(A) do begin
    Include(CharSet, A);              // fill set with array items
    if not CaseSensitive then begin      // if not case sensitive, then also
      if A in ['A'..'Z'] then
        Include(CharSet, Chr(Ord(A) + 32))  // include lower cased or
      else if A in ['a'..'z'] then
        Include(CharSet, Chr(Ord(A) - 32))  // include upper cased character
    end;
  end;
  SetLength(Result, Length(S));          // set length to prevent realloc
  count := 0;
  for i := 1 to Length(S) do begin       // iterate over string S
    if not (S in CharSet) then begin  // add good chars to Result
      Result[count + 1] := S;
      inc(Count);                        // keep track of num chars copies
    end;
  end;
  SetLength(Result, count);              // set length to num chars copied
end;
 
function LastPos(const SubStr, S: string): Integer;
var
  FoundStr: PChar;
begin
  Result := 0;
  FoundStr := StrLastPos(PChar(S), PChar(SubStr));
  if FoundStr <> nil then
    Result := (Cardinal(Length(S)) - StrLen(FoundStr)) + 1;
end;
 
procedure RealizeLength(var S: string);
begin
  SetLength(S, StrLen(PChar(S)));
end;
 
function RemoveBackSlash(const S: string): string;
begin
  Result := S;
  if Result[Length(Result)] = '\' then   // if last character is a backslash...
    DecStrLen(Result, 1);                // decrement string length
end;
 
function RemoveSpaces(const S: string): string;
begin
  Result := KillChars(S, [' '], True);
end;
 
function ReverseStr(const S: string): string;
begin
  Result := S;
  StrReverse(PChar(Result));
end;
 
{除去前后回车}
function TrimEnterLeft(S:string):string;
begin
  S:=ReverseStr(S);
  S:=TrimEnterRight(S);
  S:=ReverseStr(S);
  Result:=S;
end;
 
function TrimEnterRight(S:string):string;
begin
  while ((Length(S)>1)and((S[Length(S)]=#10)and(S[Length(S)-1]=#13)))or
   ((Length(S)>1)and((S[Length(S)]=#13)and(S[Length(S)-1]=#10))) do
  begin
    S:=Copy(S,1,Length(S)-2);
  end;
  Result:=S;
end;
 
function TrimEnter(S:string):string;
begin
  S:=TrimE
 
 
{将数字变成中文大写}
function FloatToChinaBig(Num:Double;ChinaBigFormat:TChinaBigFormat=cbfFull;Blanks:Byte=0):string;
var
  Str:string;
  AgainstStr:string;
  NumStr:string;
  i,j:Integer;
  AllNumLength:Integer;
  TempStr:string;
begin
  if Blanks>15 then Blanks:=17;
  NumStr:=CurrToStrF(Num,ffFixed,2);
  Delete(NumStr,Pos('.',NumStr),1);
  AllNumLength:=Length(NumStr);
  if Blanks<=AllNumLength then Blanks:=AllNumLength
  else begin
    TempStr:='';
    for i:=1 to Blanks-AllNumLength do
    begin
      TempStr:=TempStr+'0';
    end;
    NumStr:=TempStr+NumStr;
  end;
  NumStr:=ReverseStr(NumStr);
  Str:=FormatFloat('0佰0拾0万0仟0佰0拾0亿0仟0佰0拾0万0仟0佰0拾0圆.0角0分',Num);
  Delete(Str,Pos('.',Str),1);
  AgainstStr:=ReverseStr(Str);
  AgainstStr:=Copy(AgainstStr,1,3*Blanks);
  if ChinaBigFormat=cbfBlank then
  begin
    AgainstStr:='';
    for i:=1 to Blanks do
      AgainstStr:=AgainstStr+'  '+NumStr;
  end;
  j:=0;
  for i:=1 to Blanks do
  begin
    Insert(ReverseStr(GetChinaNum(AgainstStr[3*i+2*j])),AgainstStr,3*i+2*j);
    Inc(j);
  end;
  j:=0;
  for i:=1 to Blanks do
  begin
    Delete(AgainstStr,5*i-j,1);
    Inc(j);
  end;
  Result:=ReverseStr(AgainstStr);
end;
 
function FloatToChnStr(Value: Real; ClearZero: Boolean; full:Boolean=False): String;
const
  ChnUnit: array[0..13] of string = ('分', '角', '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟');
  ChnNum : array[0..9]  of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
var
  I: Integer;
  StrValue, StrNum: String;
  ValueLen: Integer;
begin
  if Value <= 0 then
  begin
    Result := '输入参数应大于零。';
    Exit;
  end;
  value:=RoundTo(Value,-2);
  StrValue := IntToStr(Round(Value * 100));
  ValueLen := Length(StrValue);
  Result := '';
  for I := 1 to ValueLen do
  begin
    StrNum := StrValue;
    Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
  end;
  if ClearZero then
  begin
    Result := StringReplace(Result, '零分', '',   [rfReplaceAll]);
    if Frac(Value)>0.009999 then
      Result := StringReplace(Result, '零角', '零',   [rfReplaceAll])
    else
      Result := StringReplace(Result, '零角', '',   [rfReplaceAll]);
    Result := StringReplace(Result, '零元', '元', [rfReplaceAll]);
    Result := StringReplace(Result, '零拾', '零',   [rfReplaceAll]);
    Result := StringReplace(Result, '零佰', '零',   [rfReplaceAll]);
    Result := StringReplace(Result, '零仟', '零',   [rfReplaceAll]);
    Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
    Result := StringReplace(Result, '零零', '零',   [rfReplaceAll]);
    Result := StringReplace(Result, '零零', '零',   [rfReplaceAll]);
  end;
  if full then
  begin
    if Frac(Value)<0.009999 then
      Result:=Result+'整';
  end;
end;
 
{将数字变成英文}
function FloatToEnglish(Num:Double):string;
var
  StrList:TStringList;
  i:Integer;
  StrTemp1,StrTemp2:String;
  NumArray:array [0..3] of Integer;
  NumCount:Integer;
  ResultStr:string;
  Tmp,Tmp1,Tmp2,TmpXiao:Integer;
 
  function OneNumToEng(Num:Integer;TWO:Integer=0):string;
  begin
    if Two=0 then
    begin
      case Num of
        0:Result:='ZERO';
        1:Result:='ONE';
        2:Result:='TWO';
        3:Result:='THREE';
        4:Result:='FOUR';
        5:Result:='FIVE';
        6:Result:='SIX';
        7:Result:='SEVEN';
        8:Result:='EIGHT';
        9:Result:='NINE';
      end;
    end
    else if Two=1 then
    begin
      case Num of
        1:Result:='TEN';
        2:Result:='TWENTY';
        3:Result:='THIRTY';
        4:Result:='FORTY';
        5:Result:='FIFTY';
        6:Result:='SIXTY';
        7:Result:='SEVENTY';
        8:Result:='EIGHTY';
        9:Result:='NINETY';
      end;
    end
    else if Two=2 then
    begin
      case Num of
        0:Result:='';
        1:Result:='ONE';
        2:Result:='TWO';
        3:Result:='THREE';
        4:Result:='FOUR';
        5:Result:='FIVE';
        6:Result:='SIX';
        7:Result:='SEVEN';
        8:Result:='EIGHT';
        9:Result:='NINE';
      end;
    end;
  end;
 
  function TwoNumToEng(Num:Integer):string;
  var
    NStr:string;
    One:string;
    Two:string;
    S:string;
  begin
    NStr:=IntToStr(Num);
    if Num<10 then
      Result:=OneNumToEng(Num)
    else begin
      case Num of
        10:Result:='TEN';
        11:Result:='ELEVEN';
        12:Result:='TWELVE';
        13:Result:='THIRTEEN';
        14:Result:='FOURTEEN';
        15:Result:='FIFTEEN';
        16:Result:='SIXTEEN';
        17:Result:='SEVENTEEN';
        18:Result:='EIGHTEEN';
        19:Result:='NINETEEN';
        20:Result:='TWENTY';
        30:Result:='THIRTY';
        40:Result:='FORTY';
        50:Result:='FIFTY';
        60:Result:='SIXTY';
        70:Result:='SEVENTY';
        80:Result:='EIGHTY';
        90:Result:='NINETY';
        else begin
          One:=NStr[1];
          Two:=NStr[2];
          S:=OneNumToEng(StrToInt(One),1);
          S:=S+'-'+OneNumToEng(StrToInt(Two),2);
          Result:=S;
        end;
      end;
    end;
  end;
 
  function ThreeNumToEng(Num:Integer;Hasand:Boolean=False):string;
  var
    Nstr:string;
    S:string;
    H:Integer;
    R:Integer;
  begin
    Nstr:=IntToStr(Num);
    if Num>=100 then
    begin
      H:=Num div 100;
      R:=Num mod 100;
      if R=0 then
      begin
        S:=OneNumToEng(H)+' '+'HUNDRED';
      end
      else begin
        S:=OneNumToEng(H)+' '+'HUNDRED'+' AND '+TwoNumToEng(R);
      end;
    end
    else begin
      S:=TwoNumToEng(Num);
    end;
    if Hasand then
    begin
      if S='ZERO' then
       Result:='' else
      Result:='AND '+S
    end
    else Result:=S;
  end;
 
begin
 
{0               nought;zero;O
1               one
2               two
3               three
4               four
5               five
6               six
7               seven
8               eight
9               nine
10              ten
11              eleven
12              twelve
13              thirteen
14              fourteen
15              fifteen
16              sixteen
17              seventeen
18              eighteen
19              nineteen
20              twenty
21              twenty-one
22              twenty-two
23              twenty-three
30              thirty
32              thirty-two
40              forty
50              fifty
60              sixty
70              seventy
80              eighty
90              ninety
100             one hundred
101             one hundred and one
156             one hundred and fifty-six
192             one hundred and ninety-two
200             two hundred
300             three hundred
400             four hundred
500             five hundred
600             six hundred
700             seven hundred
800             eight hundred
900             nine hundred
1,000           one thousand
1,001           one thousand and one
1,300           thirteen hundred;one thousand and three hundred
2,000           two thousand
2,034           two thousand and thirty-four
6,502           six thousand five hundred and two
38,000          thirty-eight thousand
45,672          forty-five thousand six hundred and seventy-two
500,000         five hundred thousand
1,000,000       one million
3,123,400       three million,one hundred and twenty-three thousand and four hundred
8,000,000       eight million
47,000,000      forty-seven million
900,000,000     nine hundred million
1,000,000,000   a milliard,one milliard(美作:a billion,one billion)
1,050,000,000   one billion and fifty million
10,000,000,000  ten billion
200,000,000,000 two hundred billion
1,000,000,000,000       a billion,one billion(美作:a trillion,one trillion)
6,000,000,000,000       six million million}
  if Num>2000000000 then Raise Exception.Create('数值太大');
  StrList:=TStringList.Create;
  try
    Tmp:=Trunc(Num);
    TmpXiao:=Round((Num-Tmp)*100);
//    ShowMessage(IntToStr(Tmpxiao));
    Tmp1:=Tmp div 1000;
    Tmp2:=Tmp mod 1000;
    while Tmp1>0 do
    begin
      Tmp:=Tmp1;
      StrList.Add(IntToStr(Tmp2));
      Tmp1:=Tmp div 1000;
      Tmp2:=Tmp mod 1000;
    end;
    StrList.Add(IntToStr(Tmp2));
    NumCount:=StrList.Count;
    for i:=0 to NumCount-1 do
    begin
      NumArray:=StrToInt(StrList);
    end;
    case NumCount of
      1:ResultStr:=ThreeNumToEng(NumArray[0]);
      2:ResultStr:=ThreeNumToEng(NumArray[1])+' THOUSAND '+ThreeNumToEng(NumArray[0],True);
      3:begin
        StrTemp1:=ThreeNumToEng(NumArray[1],True);
        if StrTemp1<>'' then
          ResultStr:=ThreeNumToEng(NumArray[2])+' MILLION '+
            StrTemp1+' THOUSAND '+
            ThreeNumToEng(NumArray[0],True)
        else ResultStr:=ThreeNumToEng(NumArray[2])+' MILLION '+
            ThreeNumToEng(NumArray[0],True);
      end;
      4:begin
        StrTemp2:=ThreeNumToEng(NumArray[3])+' BILLION ';
        StrTemp1:=ThreeNumToEng(NumArray[2],True);
        if StrTemp1<>'' then
          StrTemp2:=StrTemp2+StrTemp1;
        StrTemp1:=ThreeNumToEng(NumArray[1],True);
        if StrTemp1<>'' then
          StrTemp2:=StrTemp2+StrTemp1;
        ResultStr:=StrTemp2+ThreeNumToEng(NumArray[0],True);
      end;
    end;
    StrTemp1:=ThreeNumToEng(TmpXiao,True);
    if StrTemp1<>'' then
      ResultStr:=ResultStr+' AND CENTS '+Copy(StrTemp1,5,Length(StrTemp1)-4);
    Result:=ResultStr;
  finally
    StrList.Free;
  end;
end;
 
{日期用英文}
function DateToEng(ADate:TDate;th:Boolean=False):string;
var
  AYear,AMonth,ADay:Word;
  SYear,SMonth,SDay:string;
begin
  DecodeDate(ADate,AYear,AMonth,ADay);
  case AMonth of
    1:SMonth:='JAN';
    2:SMonth:='FEB';
    3:SMonth:='MAR';
    4:SMonth:='APR';
    5:SMonth:='MAY';
    6:SMonth:='JUN';
    7:SMonth:='JUL';
    8:SMonth:='AUG';
    9:SMonth:='SEP';
    10:SMonth:='OCT';
    11:SMonth:='NOV';
    12:SMonth:='DEC';
  end;
  SDay:=IntToStr(ADay);
  if th then
  begin
    case ADay of
      1,21,31:SDay:=SDay+'st';
      2,22,23:SDay:=SDay+'nd';
      3:SDay:=SDay+'rd';
      4..20:SDay:=SDay+'th';
      24..30:SDay:=SDay+'st';
    end;
  end;
  SYear:=IntToStr(AYear);
  Result:=SMonth+' '+SDay+','+SYear;
end;
 
{字符串取反}
{function GetAgainstStr(Str:string):string;
var
  i,StrLength:Integer;
  TmpStr:string;
begin
  StrLength:=Length(Str);
  SetLength(TmpStr,StrLength);
  for i:=1 to StrLength do TmpStr:=Str[StrLength+1-i];
  Result:=TmpStr;
end;}
 
{取得SQL日期字符串}
function DateToSQLDateStr(ADate:TDateTime):string;
begin
  Result:=FormatDateTime('mm"/"dd"/"yyyy',ADate);
end;
 
function StrToSQLDateStr(Str:string):string;
var
  StrDate:TDateTime;
begin
  StrDate:=StrToDateTime(Str);
  Result:=DateToSQLDateStr(StrDate);
end;
 
function TimeToSQLTimeStr(ATime:TDateTime):string;
begin
  Result:=FormatDateTime('hh":"nn":"ss',ATime);
end;
 
function StrToSQLTimeStr(Str:string):string;
var
  StrTime:TDateTime;
begin
  StrTime:=StrToDateTime(Str);
  Result:=TimeToSQLTimeStr(StrTime);
end;
 
function DateTimeToSQLDateTimeStr(ADateTime:TDateTime):string;
begin
  Result:=FormatDateTime('mm"/"dd"/"yyyy hh":"nn":"ss',ADateTime);
end;
 
function StrToSQLDateTimeStr(Str:string):string;
var
  StrDateTime:TDateTime;
begin
  StrDateTime:=StrToDateTime(Str);
  Result:=DateTimeToSQLDateTimeStr(StrDateTime);
end;
 
{返回有逗号的金额字符串}
function FloatToMoneyStr(Num:Double;const HasSymbol:Boolean=False):string;
begin
  if HasSymbol then Result:=CurrToStrF(Num,ffCurrency,2)
  else Result:=CurrToStrF(Num,ffNumber,2);
end;
 
{Bool与字符串的转换}
function StrToBool(const Str:string):Boolean;
begin
  if CompareText('True',Str)=0 then Result:=True
  else Result:=False;
end;
 
function BoolToStr(const Bool:Boolean):string;
begin
  if Bool then Result:='True'
  else Result:='False';
end;
 
{判断是否日期等}
type
  TDateOrder = (doMDY, doDMY, doYMD);
 
function CurrentYear: Word;
var
  SystemTime: TSystemTime;
begin
  GetLocalTime(SystemTime);
  Result := SystemTime.wYear;
end;
 
function DoEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
begin
  Result := False;
  if (Hour < 24) and (Min < 60) and (Sec < 60) and (MSec < 1000) then
  begin
    Time := (Hour * 3600000 + Min * 60000 + Sec * 1000 + MSec) / MSecsPerDay;
    Result := True;
  end;
end;
 
function DoEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
var
  I: Integer;
  DayTable: PDayTable;
begin
  Result := False;
  DayTable := @MonthDays[IsLeapYear(Year)];
  if (Year >= 1) and (Year <= 9999) and (Month >= 1) and (Month <= 12) and
    (Day >= 1) and (Day <= DayTable^[Month]) then
  begin
    for I := 1 to Month - 1 do Inc(Day, DayTable^);
    I := Year - 1;
    Date := I * 365 + I div 4 - I div 100 + I div 400 + Day - DateDelta;
    Result := True;
  end;
end;
 
procedure ScanBlanks(const S: string; var Pos: Integer);
var
  I: Integer;
begin
  I := Pos;
  while (I <= Length(S)) and (S = ' ') do Inc(I);
  Pos := I;
end;
 
function ScanNumber(const S: string; var Pos: Integer;
  var Number: Word; var CharCount: Byte): Boolean;
var
  I: Integer;
  N: Word;
begin
  Result := False;
  CharCount := 0;
  ScanBlanks(S, Pos);
  I := Pos;
  N := 0;
  while (I <= Length(S)) and (S in ['0'..'9']) and (N < 1000) do
  begin
    N := N * 10 + (Ord(S) - Ord('0'));
    Inc(I);
  end;
  if I > Pos then
  begin
    CharCount := I - Pos;
    Pos := I;
    Number := N;
    Result := True;
  end;
end;
 
function ScanString(const S: string; var Pos: Integer;
  const Symbol: string): Boolean;
begin
  Result := False;
  if Symbol <> '' then
  begin
    ScanBlanks(S, Pos);
    if AnsiCompareText(Symbol, Copy(S, Pos, Length(Symbol))) = 0 then
    begin
      Inc(Pos, Length(Symbol));
      Result := True;
    end;
  end;
end;
 
function ScanChar(const S: string; var Pos: Integer; Ch: Char): Boolean;
begin
  Result := False;
  ScanBlanks(S, Pos);
  if (Pos <= Length(S)) and (S[Pos] = Ch) then
  begin
    Inc(Pos);
    Result := True;
  end;
end;
 
function GetDateOrder(const DateFormat: string): TDateOrder;
var
  I: Integer;
begin
  Result := doMDY;
  I := 1;
  while I <= Length(DateFormat) do
  begin
    case Chr(Ord(DateFormat) and $DF) of
      'E': Result := doYMD;
      'Y': Result := doYMD;
      'M': Result := doMDY;
      'D': Result := doDMY;
    else
      Inc(I);
      Continue;
    end;
    Exit;
  end;
  Result := doMDY;
end;
 
procedure ScanToNumber(const S: string; var Pos: Integer);
begin
  while (Pos <= Length(S)) and not (S[Pos] in ['0'..'9']) do
  begin
    if S[Pos] in LeadBytes then Inc(Pos);
    Inc(Pos);
  end;
end;
 
function GetEraYearOffset(const Name: string): Integer;
var
  I: Integer;
begin
  Result := 0;
  for I := Low(EraNames) to High(EraNames) do
  begin
    if EraNames = '' then Break;
    if AnsiStrPos(PChar(EraNames), PChar(Name)) <> nil then
    begin
      Result := EraYearOffsets;
      Exit;
    end;
  end;
end;
 
function ScanDate(const S: string; var Pos: Integer;
  var Date: TDateTime): Boolean;
var
  DateOrder: TDateOrder;
  N1, N2, N3, Y, M, D: Word;
  L1, L2, L3, YearLen: Byte;
  EraName : string;
  EraYearOffset: Integer;
  CenturyBase: Integer;
 
  function EraToYear(Year: Integer): Integer;
  begin
    if SysLocale.PriLangID = LANG_KOREAN then
    begin
      if Year <= 99 then
        Inc(Year, (CurrentYear + Abs(EraYearOffset)) div 100 * 100);
      if EraYearOffset > 0 then
        EraYearOffset := -EraYearOffset;
    end
    else
      Dec(EraYearOffset);
    Result := Year + EraYearOffset;
  end;
 
begin
  Y := 0;
  M := 0;
  D := 0;
  YearLen := 0;
  Result := False;
  DateOrder := GetDateOrder(ShortDateFormat);
  EraYearOffset := 0;
  if ShortDateFormat[1] = 'g' then  // skip over prefix text
  begin
    ScanToNumber(S, Pos);
    EraName := Trim(Copy(S, 1, Pos-1));
    EraYearOffset := GetEraYearOffset(EraName);
  end
  else
    if AnsiPos('e', ShortDateFormat) > 0 then
      EraYearOffset := EraYearOffsets[1];
  if not (ScanNumber(S, Pos, N1, L1) and ScanChar(S, Pos, DateSeparator) and
    ScanNumber(S, Pos, N2, L2)) then Exit;
  if ScanChar(S, Pos, DateSeparator) then
  begin
    if not ScanNumber(S, Pos, N3, L3) then Exit;
    case DateOrder of
      doMDY: begin Y := N3; YearLen := L3; M := N1; D := N2; end;
      doDMY: begin Y := N3; YearLen := L3; M := N2; D := N1; end;
      doYMD: begin Y := N1; YearLen := L1; M := N2; D := N3; end;
    end;
    if EraYearOffset > 0 then
      Y := EraToYear(Y)
    else if (YearLen <= 2) then
    begin
      CenturyBase := CurrentYear - TwoDigitYearCenturyWindow;
      Inc(Y, CenturyBase div 100 * 100);
      if (TwoDigitYearCenturyWindow > 0) and (Y < CenturyBase) then
        Inc(Y, 100);
    end;
  end else
  begin
    Y := CurrentYear;
    if DateOrder = doDMY then
    begin
      D := N1; M := N2;
    end else
    begin
      M := N1; D := N2;
    end;
  end;
  ScanChar(S, Pos, DateSeparator);
  ScanBlanks(S, Pos);
  if SysLocale.FarEast and (System.Pos('ddd', ShortDateFormat) <> 0) then
  begin     // ignore trailing text
    if ShortTimeFormat[1] in ['0'..'9'] then  // stop at time digit
      ScanToNumber(S, Pos)
    else  // stop at time prefix
      repeat
        while (Pos <= Length(S)) and (S[Pos] <> ' ') do Inc(Pos);
        ScanBlanks(S, Pos);
      until (Pos > Length(S)) or
        (AnsiCompareText(TimeAMString, Copy(S, Pos, Length(TimeAMString))) = 0) or
        (AnsiCompareText(TimePMString, Copy(S, Pos, Length(TimePMString))) = 0);
  end;
  Result := DoEncodeDate(Y, M, D, Date);
end;
 
function ScanTime(const S: string; var Pos: Integer;
  var Time: TDateTime): Boolean;
var
  BaseHour: Integer;
  Hour, Min, Sec, MSec: Word;
  Junk: Byte;
begin
  Result := False;
  BaseHour := -1;
  if ScanString(S, Pos, TimeAMString) or ScanString(S, Pos, 'AM') then
    BaseHour := 0
  else if ScanString(S, Pos, TimePMString) or ScanString(S, Pos, 'PM') then
    BaseHour := 12;
  if BaseHour >= 0 then ScanBlanks(S, Pos);
  if not ScanNumber(S, Pos, Hour, Junk) then Exit;
  Min := 0;
  if ScanChar(S, Pos, TimeSeparator) then
    if not ScanNumber(S, Pos, Min, Junk) then Exit;
  Sec := 0;
  if ScanChar(S, Pos, TimeSeparator) then
    if not ScanNumber(S, Pos, Sec, Junk) then Exit;
  MSec := 0;
  if ScanChar(S, Pos, DecimalSeparator) then
    if not ScanNumber(S, Pos, MSec, Junk) then Exit;
  if BaseHour < 0 then
    if ScanString(S, Pos, TimeAMString) or ScanString(S, Pos, 'AM') then
      BaseHour := 0
    else
      if ScanString(S, Pos, TimePMString) or ScanString(S, Pos, 'PM') then
        BaseHour := 12;
  if BaseHour >= 0 then
  begin
    if (Hour = 0) or (Hour > 12) then Exit;
    if Hour = 12 then Hour := 0;
    Inc(Hour, BaseHour);
  end;
  ScanBlanks(S, Pos);
  Result := DoEncodeTime(Hour, Min, Sec, MSec, Time);
end;
 
function IsDate(const CheckString:string):Boolean;
var
  Pos: Integer;
  Date:TDateTime;
begin
  Pos := 1;
  Result:=ScanDate(CheckString, Pos, Date) or (Pos <= Length(CheckString)); 
end;
 
function IsDateTime(const CheckString:string):Boolean;
var
  Pos,Pos1: Integer;
  Date, Time: TDateTime;
  DateTime:TDateTime;
begin
  Pos := 1;
  Pos1:=1;
  Time := 0;
  Result:=ScanDate(CheckString,Pos,Date) or not ((Pos > Length(CheckString)) or
    ScanTime(CheckString, Pos, Time)) or
      (ScanTime(CheckString, Pos1, DateTime) or (Pos1 <= Length(CheckString)));
end;
 
function IsTime(const CheckString:string):Boolean;
var
  Pos: Integer;
  v:TDateTime;
begin
  Pos := 1;
  Result:=ScanTime(CheckString, Pos, v) or (Pos <= Length(CheckString))
end;
 
{$HINTS OFF}
function IsInteger(const CheckString:string):Boolean;
var
  V,Code:Integer;
begin
  Val(CheckString,V,Code);
  Result := code = 0;
end;
{$HINTS ON}
 
function IsFloat(const CheckString:string):Boolean;
var
  V:Extended;
begin
  Result:=TextToFloat(PChar(CheckString), V, fvExtended);
end;
 
{多字符串ShowMessage}
procedure ShowMessages(const Strings:array of string);
var
  i:Integer;
  S:string;
begin
  for i:=Low(Strings) to High(Strings) do
  begin
    S:=S+Strings+#13#10;
  end;
  ShowMessage(S);
end;
 
{新名称}
function NameToNewName(const Str:string):string;
var
  StrPart,NumPart:string;
  i,LengStr:Integer;
begin
  LengStr:=Length(Str);
  i:=LengStr;
  if Str in ['0'..'9'] then
  begin
    NumPart:=Str+NumPart;
    Dec(i);
    while Str in ['1'..'9'] do
    begin
      NumPart:=Str+NumPart;
      Dec(i);
    end;
  end;
  StrPart:=Copy(Str,1,i);
  if Length(NumPart)=0 then NumPart:='1'
  else NumPart:=IntToStr(StrToInt(NumPart)+1);
  Result:=StrPart+NumPart;
end;

转载于:https://www.cnblogs.com/kaibosoft/p/4039171.html

Win32.pas API函数的简单调用,如建立进程,建立文件映射,建立、读取管道(可以捕捉DOS程序输出)等。 StrFuncs.pas 字符串处理单元,完全兼容宽字节处理(即使用wideString),特有的中文字符串处理函数(如简繁转换等等),经过多次优化,大多以编表的方式进行处理(一般来说是最快的处理方式)。 BiosHelp.pas  读取Bios信息的单元,兼容各种windows系统。 Streams.pas  流(TStream)输入输出处理单元,可以用来保存读取控件属性。 ShlFile.pas  各种文件操作,包括获得系统特殊路径,获取文件图标等。 RegExpr.pas  一个规则表达式类的单元。 ShareMemRep.pas  一个可以用来替代Delphi本身的内存管理的单元。 MessageDlg.pas 提供了一个高制定性的消息对话框。 Lists.pas  提供了很多个TList的扩展类,是学习很研究TList的好东西。 Calendar.pas  公历与农历换算和时间处理的函数单元,具体看里面的说明。 Clipboards.pas 提供一个剪贴板增强类,可支持保存和载入剪贴板,支持多重剪贴板。 ComputerInfo.pas 完整的系统信息检测单元,从软件到硬件,从CPU到鼠标,很全面。 AccessCtrls.pas 一个Access数据库操作单元。 FastIniFile.pas  可以用来替换DELPHI提供的慢吞吞的IniFiles单元,并且支持更多写入读出类型。 EnumStuff.pas 一个募举进程和窗口列表的单元,兼容各种Windows系统。 DES.pas  DES加密算法单元。 AES.pas  AES加密算法单元。 CryptoAPI.pas  一个完整的Hash算法单元,如MD5、CRC之类等等。 FastMM.pas  国外很著名的内存管理单元,Delphi2006的内存管理单元用的就是它。 FastStrings.pas  一个快速字符串处理单元,一些函数用汇编写的,处理速度比DELPHI本身的字符串处理快很多,不过不支持WideString类型。 Idpacker.pas  压缩文件类型检测单元。 ZLibEx.pas  纯Pascal代码的快速压缩解压单元,压缩率和速度都不错。 FastStringFuncs.pas  基于FastStrings.pas单元的应用。
//▎============================================================▎// //▎================① 扩展的字符串操作函数 ===================▎// //▎============================================================▎// //从文件中返回Ado连接字串。 function GetConnectionString(DataBaseName:string):string; //返回服务器的机器名称. function GetRemoteServerName:string; function InStr(const sShort: string; const sLong: string): Boolean; {测试通过} {* 判断s1是否包含在s2中} function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'): string; {测试通过} {* 扩展整数转字符串函数 Example: IntToStrEx(1,5,'0'); 返回:"00001"} function IntToStrSp(Value: Integer; SpLen: Integer = 3; Sp: Char = ','): string; {测试通过} {* 带分隔符的整数-字符转换} function ByteToBin(Value: Byte): string; {测试通过} {* 字节转二进制串} function StrRight(Str: string; Len: Integer): string; {测试通过} {* 返回字符串右边的字符 Examples: StrRight('ABCEDFG',3); 返回:'DFG' } function StrLeft(Str: string; Len: Integer): string; {测试通过} {* 返回字符串左边的字符} function Spc(Len: Integer): string; {测试通过} {* 返回空格串} function Replace(Str,s1,s2:string;CaseSensitive:Boolean):string; {测试通过} {* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} {example: replace('We know what we want','we','I',false) = 'I Know what I want'} function Replicate(pcChar:Char; piCount:integer):string; {在一个字符串中查找某个字符串的位置} function StrNum(ShortStr:string;LongString:string):Integer; {测试通过} {* 返回某个字符串中某个字符串中出现的次数} function FindStr(ShortStr:String;LongStrIng:String):Integer; {测试通过} {* 返回某个字符串中查找某个字符串的位置} function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String; {测试通过} {* 返回从位置BeginPlace开始切取长度为CatLeng字符串} function LeftStr(psInput:String; CutLeng:Integer):String; {测试通过} {* 返回从左边第一为开始切取 CutLeng长度的字符串} function RightStr(psInput:String; CutLeng:Integer):String; {测试通过} {* 返回从右边第一为开始切取 CutLeng长度的字符串} function PadLStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串左边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadRStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串右边开始用pcPadWith填充后总长度为PiWidth的字符串} function PadCStr(psInput:String; piWidth:Integer; pcPadWith:Char):String; {测试通过} {* 返回从psInput字符串两边开始用pcPadWith填充后总长度为PiWidth的字符串} function ChrTran(psInput:String; pcSearch:Char; pcTranWith:Char):String; {测试通过} {* 返回替换后字符串[替换单个字符] Examples: ChrTran('abCdEgdlkh','d','#'); 返回'abC#Eg#lkh'} function StrTran(psInput:String; psSearch:String; psTranWith:String):String; {测试通过} {* 返回替换后字符串[替换字符串] Examples: StrTran('aruyfbn','ruy','=====');; 返回'a=====fbn'} function Stuff(psInput:String; piBeginPlace,piCount:Integer; psStuffWith:String):String; { *返回替换后字符串[替换字符串] Examples: Stuff('ABCDEFGHI',3,4,'12345');返回'AB12345GHI'} procedure SwapStr(var s1, s2: string); {测试通过} {* 交换字串} function LinesToStr(const Lines: string): string; {测试通过} {* 多行文本转单行(换行符转'\n')} function StrToLines(const Str: string): string; {测试通过} {* 单行文本转多行('\n'转换行符)} function Encrypt(const S: String; Key: Word): String; {* 字符串加密函数} function Decrypt(const S: String; Key: Word): String; {* 字符串解密函数} function varIIF(aTest: Boolean; TrueValue, FalseValue: Variant): Variant; function varToStr(const V: Variant): string; {* VarIIF及VartoStr为变体函数} function IsDigital(Value: string): boolean; {功能说明:判断string是否全是数字} function RandomStr(aLength : Longint) : String; {随机字符串函数} //▎============================================================▎// //▎================② 扩展的日期时间操作函数 =================▎// //▎============================================================▎// function GetYear(Date: TDate): Integer; {测试通过} {* 取日期年份分量} function GetMonth(Date: TDate): Integer; {测试通过} {* 取日期月份分量} function GetDay(Date: TDate): Integer; {测试通过} {* 取日期天数分量} function GetHour(Time: TTime): Integer; {测试通过} {* 取时间小时分量} function GetMinute(Time: TTime): Integer; {测试通过} {* 取时间分钟分量} function GetSecond(Time: TTime): Integer; {测试通过} {* 取时间秒分量} function GetMSecond(Time: TTime): Integer; {测试通过} {* 取时间毫秒分量} function GetMonthLastDay(Cs_Year,Cs_Month:string):string; { *传入年、月,得到该月份最后一天} function IsLeapYear( nYear: Integer ): Boolean; {*/判断某年是否为闰年} function MaxDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较大的日期} function MinDateTime(const Values: array of TDateTime): TDateTime; {//两个日期取较小的日期} function dateBeginOfMonth(D: TDateTime): TDateTime; {//得到本月的第一天} function DateEndOfMonth(D: TDateTime): TDateTime; {//得到本月的最后一天} function DateEndOfYear(D: TDateTime): TDateTime; {//得到本年的最后一天} function DaysBetween(Date1, Date2: TDateTime): integer; {//得到两个日期相隔的天数} //▎============================================================▎// //▎===================③ 扩展的位操作函数 ====================▎// //▎============================================================▎// type TByteBit = 0..7; {* Byte类型位数范围} TWordBit = 0..15; {* Word类型位数范围} TDWordBit = 0..31; {* DWord类型位数范围} procedure SetBit(var Value: Byte; Bit: TByteBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: WORD; Bit: TWordBit; IsSet: Boolean); overload; {* 设置二进制位} procedure SetBit(var Value: DWORD; Bit: TDWordBit; IsSet: Boolean); overload; {* 设置二进制位} function GetBit(Value: Byte; Bit: TByteBit): Boolean; overload; {* 取二进制位} function GetBit(Value: WORD; Bit: TWordBit): Boolean; overload; {* 取二进制位} function GetBit(Value: DWORD; Bit: TDWordBit): Boolean; overload; {* 取二进制位} //▎============================================================▎// //▎=================④扩展的文件及目录操作函数=================▎// //▎============================================================▎// function MoveFile(const sName, dName: string): Boolean; {测试通过} {* 移动文件、目录,参数为源、目标名} procedure FileProperties(const FName: string); {测试通过} {* 打开文件属性窗口} function CreatePath(path : string) : Boolean; function OpenDialog(var FileName: string; Title: string; Filter: string; Ext: string): Boolean; {* 打开文件框} function FormatPath(APath: string; Width: Integer): string; {测试通过} {* 缩短显示不下的长路径名} function GetRelativePath(Source, Dest: string): string; {测试通过} {* 取两个目录的相对路径,注意串尾不能是'\'字符!} procedure RunFile(const FName: string; Handle: THandle = 0; const Param: string = ''); {测试通过} {* 运行一个文件} function WinExecAndWait32(FileName: string; Visibility: Integer = SW_NORMAL): Integer; {测试通过} {* 运行一个文件并等待其结束} function AppPath: string; {测试通过} {* 应用程序路径} function GetDiskInfo(sFile : string; var nDiskFree,nDiskSize : Int64): boolean; {测试通过} {* 取sFile 所在磁盘空间状态 } function GetWindowsDir: string; {测试通过} {* 取Windows系统目录} function GetWinTempDir: string; {测试通过} {* 取临时文件目录} function AddDirSuffix(Dir: string): string; {测试通过} {* 目录尾加'\'修正} function MakePath(Dir: string): string; {测试通过} {* 目录尾加'\'修正} function IsFileInUse(FName: string): Boolean; {测试通过} {* 判断文件是否正在使用} function GetFileSize(FileName: string): Integer; {测试通过} {* 取文件长度} function SetFileDate(FileName: string; CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 设置文件时间 Example: FileSetDate('c:\Test\Test1.exe',753160662); } function GetFileDate(FileName: string; var CreationTime, LastWriteTime, LastAccessTime: TFileTime): Boolean; {测试通过} {* 取文件时间} function FileTimeToLocalSystemTime(FTime: TFileTime): TSystemTime; {测试通过} {* 文件时间转本地时间} function LocalSystemTimeToFileTime(STime: TSystemTime): TFileTime; {测试通过} {* 本地时间转文件时间} function GetFileIcon(FileName: string; var Icon: TIcon): Boolean; {测试通过} {* 取得与文件相关的图标,成功则返回True} function CreateBakFile(FileName, Ext: string): Boolean; {测试通过} {* 创建备份文件} function Deltree(Dir: string): Boolean; {测试通过} {* 删除整个目录} function GetDirFiles(Dir: string): Integer; {测试通过} {* 取文件夹文件数} type TFindCallBack = procedure(const FileName: string; const Info: TSearchRec; var Abort: Boolean); {* 查找指定目录下文件的回调函数} procedure FindFile(const Path: string; const FileName: string = '*.*'; Proc: TFindCallBack = nil; bSub: Boolean = True; const bMsg: Boolean = True); {* 查找指定目录下文件} procedure FindFileList(Path:string;Filter,FileList:TStrings;ContainSubDir:Boolean; lb: TLabel=nil); { 功能说明:查找一个路径下的所有文件。 参数: path:路径,filter:文件扩展名过滤,FileList:文件列表, ContainSubDir:是否包含子目录} function Txtline(const txt: string): integer; {* 返回一文本文件的行数} function Html2Txt(htmlfilename: string): string; {* Html文件转化成文本文件} function OpenWith(const FileName: string): Integer; {测试通过} {* 文件打开方式} //▎============================================================▎// //▎====================⑤扩展的对话框函数======================▎// //▎============================================================▎// procedure InfoDlg(Mess: string; Caption: string = SCnInformation; Flags: Integer = MB_OK + MB_ICONINFORMATION); {测试通过} {* 显示提示窗口} function InfoOk(Mess: string; Caption: string = SCnInformation): Boolean; {测试通过} {* 显示提示确认窗口} procedure ErrorDlg(Mess: string; Caption: string = SCnError); {测试通过} {* 显示错误窗口} procedure WarningDlg(Mess: string; Caption: string = SCnWarning); {测试通过} {* 显示警告窗口} function QueryDlg(Mess: string; Caption: string = SCnInformation): Boolean; {测试通过} {* 显示查询是否窗口} procedure SetWindowAnimate(Sender : TForm; IsSetAni : bool); //▎============================================================▎// //▎=====================⑥系统功能函数=========================▎// //▎============================================================▎// procedure MoveMouseIntoControl(AWinControl: TControl); {测试通过} {* 移动鼠标到控件} function DynamicResolution(x, y: WORD): Boolean; {测试通过} {* 动态设置分辨率} procedure StayOnTop(Handle: HWND; OnTop: Boolean); {测试通过} {* 窗口最上方显示} procedure SetHidden(Hide: Boolean); {测试通过} {* 设置程序是否出现在任务栏} procedure SetTaskBarVisible(Visible: Boolean); {测试通过} {* 设置任务栏是否可见} procedure SetDesktopVisible(Visible: Boolean); {测试通过} {* 设置桌面是否可见} procedure BeginWait; {测试通过} {* 显示等待光标} procedure EndWait; {测试通过} {* 结束等待光标} function CheckWindows9598NT: string; {测试通过} {* 检测是否Win95/98/NT平台} function GetOSInfo : String; {测试通过} {* 取得当前操作平台是 Windows 95/98 还是NT} function GetCurrentUserName : string; {*获取当前Windows登录名的用户} function GetRegistryOrg_User(UserKeyType:string):string; {*获取当前注册的单位及用户名称} function GetSysVersion:string; {*//获取操作系统版本号} function WinBootMode:string; {//Windows启动模式} type PShutType = (UPowerOff, UShutdown, UReboot, ULogOff, USuspend, UHibernate); procedure WinShutDown(ShutWinType:PShutType; PForce:Boolean); {//Windows ShutDown等} //▎============================================================▎// //▎=====================⑦硬件功能函数=========================▎// //▎============================================================▎// function GetClientGUID:string; { 功能描述:在本机上得到一个GUID.去掉两端的大括号和中间的横线 返回值:去掉两端的大括号和中间的横线的一个GUID 适用范围:windows } function SoundCardExist: Boolean; {测试通过} {* 声卡是否存在} function GetDiskSerial(DiskChar: Char): string; {* 获取磁盘序列号} function DiskReady(Root: string) : Boolean; {*检查磁盘准备是否就绪} procedure WritePortB( wPort : Word; bValue : Byte ); {* 写串口} function ReadPortB( wPort : Word ) : Byte; {*读串口} function CPUSpeed: Double; {* 获知当前机器CPU的速率(MHz)} type TCPUID = array[1..4] of Longint; function GetCPUID : TCPUID; assembler; register; {*获取CPU的标识ID号*} function GetMemoryTotalPhys : Dword; {*获取计算机的物理内存} type TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES); function DriveState (driveletter: Char) : TDriveState; {* 检查驱动器A中磁盘是否有效} //▎============================================================▎// //▎=====================⑧网络功能函数=========================▎// //▎============================================================▎// function GetComputerName:string; {* 获取网络计算机名称} function GetHostIP:string; {* 获取计算机的IP地址} function NetUserChangePassword(Domain:PWideChar; UserName:PWideChar; OldPassword:PWideChar; NewPassword:PWideChar): LongInt; stdcall; external 'netapi32.dll' name 'NetUserChangePassword'; {* // 运行平台:Windows NT/2000/XP {* // Windows 95/98/Me平台:可以用该函数修改用户的Windows登录密码} //▎============================================================▎// //▎=====================⑨汉字拼音功能函数=====================▎// //▎============================================================▎// function GetHzPy(const AHzStr: string): string; {测试通过} {* 取汉字的拼音} function HowManyChineseChar(Const s:String):Integer; {* 判断一个字符串中有多少各汉字} //▎============================================================▎// //▎===================⑩数据库功能函数及过程===================▎// //▎============================================================▎// {function PackDbDbf(Var StatusMsg: String): Boolean;} {* 物理删除数据库(Db,Dbf)中的数据[着了删除标记的记录]} procedure RepairDb(DbName: string); {* 修复Access表} function CreateODBCCfgInRegistry(ODBCSourceName:WideString;ServerName, DataBaseDescription:String):boolean; {* 通过注册表创建ODBC配置[创建在系统DSN页下]} function ADOConnectSysBase(Const Adocon:TadoConnection):boolean; {* 用Ado连接SysBase数据库函数} function ADOConnectLocalDB(Const Adocon:TadoConnection;Const Dbname,DbServerName:string;ValidateMode:Integer):boolean; {* 用Ado连接数据库函数} function ADOODBCConnectLocalDB(Const Adocon:TadoConnection;Const Dbname:string;ValidateMode:Integer):boolean; {* 用Ado与ODBC共同连接数据库函数} function CreatTable(LpDataBaseName,LpTableName,LpSentence:string):Boolean; {* //建立新表} function AddField(LpFieldName:string; LpDataType: TFieldType; LpSize: Word):string; {*//在表中添加字段} function KillField(LpFieldName:string):String; {* //在表中删除字段} function AlterTableExec(LpDataBaseName,LpSentence:string):Boolean; {* //修改表结构} function GetSQLSentence(LpTableName,LpSQLsentence:string): string; {* /修改、添加、删除表结构时的SQL句体} //▎============================================================▎// //▎======================⑾进制函数及过程======================▎// //▎============================================================▎// function StrToHex(AStr: string): string; {* 字符转化成十六进制} function HexToStr(AStr: string): string; {* 十六进制转化成字符} function TransChar(AChar: Char): Integer; //▎============================================================▎// //▎=====================⑿其它函数及过程=======================▎// //▎============================================================▎// function TrimInt(Value, Min, Max: Integer): Integer; overload; {测试通过} {* 输出限制在Min..Max之间} function IntToByte(Value: Integer): Byte; overload; {测试通过} {* 输出限制在0..255之间} function InBound(Value: Integer; Min, Max: Integer): Boolean; {测试通过} {* 判断整数Value是否在Min和Max之间} procedure CnSwap(var A, B: Byte); overload; {* 交换两个数} procedure CnSwap(var A, B: Integer); overload; {* 交换两个数} procedure CnSwap(var A, B: Single); overload; {* 交换两个数} procedure CnSwap(var A, B: Double); overload; {* 交换两个数} function RectEqu(Rect1, Rect2: TRect): Boolean; {* 比较两个Rect是否相等} procedure DeRect(Rect: TRect; var x, y, Width, Height: Integer); {* 分解一个TRect为左上角坐标x, y和宽度Width、高度Height} function EnSize(cx, cy: Integer): TSize; {* 返回一个TSize类型} function RectWidth(Rect: TRect): Integer; {* 计算TRect的宽度} function RectHeight(Rect: TRect): Integer; {* 计算TRect的高度} procedure Delay(const uDelay: DWORD); {测试通过} {* 延时} procedure BeepEx(const Freq: WORD = 1200; const Delay: WORD = 1); {Win9X下测试通过} {* 只能在Win9X下让喇叭发声} procedure ShowLastError; {测试通过} {* 显示Win32 Api运行结果信息} function writeFontStyle(FS: TFontStyles; inifile: string; write: boolean):string; {* 将字体Font.Style写入INI文件} function readFontStyle(inifile: string): TFontStyles; {* 从INI文件中读取字体Font.Style文件} //function ReadCursorPos(SourceMemo: TMemo): TPoint; function ReadCursorPos(SourceMemo: TMemo): string; {* 取得TMemo 控件当前光标的行和列信息到Tpoint中} function CanUndo(AMemo: TMemo): Boolean; {* 检查Tmemo控件能否Undo} procedure Undo(Amemo: Tmemo); {*实现Undo功能} procedure AutoListDisplay(ACombox:TComboBox); {* 实现ComBoBox自动下拉} function UpperMoney(small:real):string; {* 小写金额转换为大写 } function Myrandom(Num: Integer): integer; {*利用系统时间产生随机数)} procedure OpenIME(ImeName: string); {*打开输入法} procedure CloseIME; {*关闭输入法} procedure ToChinese(hWindows: THandle; bChinese: boolean); {*打开中文输入法} //数据备份 procedure BackUpData(LpBackDispMessTitle:String); procedure ImageLoadGif(Picture: TPicture; filename: string); procedure ImageLoadJpg(Picture: TPicture; filename: string);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值