Changeset 31 for Common/UCommon.pas


Ignore:
Timestamp:
Jun 24, 2010, 4:18:03 PM (14 years ago)
Author:
george
Message:
  • Opravy a rozšíření funkčností některých tříd
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r26 r31  
    44
    55uses
    6   Windows, SysUtils, ShFolder;
     6  Windows, SysUtils, ShFolder, ShellAPI;
    77
    88type
    99  TArrayOfByte = array of Byte;
    1010  TArrayOfString = array of string;
    11  
     11
     12function DelTree(DirName : string): Boolean;
    1213function IntToBin(Data: Cardinal; Count: Byte): string;
    1314function TryHexToInt(Data: string; var Value: Integer): Boolean;
     
    1819function GetUserName: string;
    1920function SplitString(var Text: string; Count: Word): string;
     21function GetBit(Variable: QWord; Index: Byte): Boolean;
     22procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean);
     23procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean);
     24procedure SetBit(var Variable: Word; Index: Byte; State: Boolean);
     25function AddLeadingZeroes(const aNumber, Length : integer) : string;
    2026
    2127implementation
     28
     29function DelTree(DirName : string): Boolean;
     30var
     31  SHFileOpStruct : TSHFileOpStruct;
     32  DirBuf : array [0..255] of char;
     33begin
     34  DirName := UTF8Decode(DirName);
     35  try
     36    Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0) ;
     37    FillChar(DirBuf, Sizeof(DirBuf), 0 ) ;
     38    StrPCopy(DirBuf, DirName) ;
     39    with SHFileOpStruct do begin
     40      Wnd := 0;
     41      pFrom := @DirBuf;
     42      wFunc := FO_DELETE;
     43      fFlags := FOF_ALLOWUNDO;
     44      fFlags := fFlags or FOF_NOCONFIRMATION;
     45      fFlags := fFlags or FOF_SILENT;
     46    end;
     47    Result := (SHFileOperation(SHFileOpStruct) = 0) ;
     48  except
     49     Result := False;
     50  end;
     51end;
    2252
    2353function BCDToInt(Value: Byte): Byte;
     
    3262  Path: array[0..MAX_PATH] of Char;
    3363begin
     64  Result := 'C:\Test';
    3465  if SUCCEEDED(SHGetFolderPath(0, Folder, 0, SHGFP_TYPE_CURRENT, @path[0])) then
    3566    Result := path
     
    133164end;
    134165
     166function GetBit(Variable:QWord;Index:Byte):Boolean;
     167begin
     168  Result := ((Variable shr Index) and 1) = 1;
     169end;
     170
     171procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload;
     172begin
     173  Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index);
     174end;
     175
     176procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload;
     177begin
     178  Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index);
     179end;
     180
     181procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload;
     182begin
     183  Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index);
     184end;
     185
     186function AddLeadingZeroes(const aNumber, Length : integer) : string;
     187begin
     188  Result := SysUtils.Format('%.*d', [Length, aNumber]) ;
     189end;
     190
    135191end.
Note: See TracChangeset for help on using the changeset viewer.