- Timestamp:
- Jun 24, 2010, 4:18:03 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UCommon.pas
r26 r31 4 4 5 5 uses 6 Windows, SysUtils, ShFolder ;6 Windows, SysUtils, ShFolder, ShellAPI; 7 7 8 8 type 9 9 TArrayOfByte = array of Byte; 10 10 TArrayOfString = array of string; 11 11 12 function DelTree(DirName : string): Boolean; 12 13 function IntToBin(Data: Cardinal; Count: Byte): string; 13 14 function TryHexToInt(Data: string; var Value: Integer): Boolean; … … 18 19 function GetUserName: string; 19 20 function SplitString(var Text: string; Count: Word): string; 21 function GetBit(Variable: QWord; Index: Byte): Boolean; 22 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); 23 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); 24 procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); 25 function AddLeadingZeroes(const aNumber, Length : integer) : string; 20 26 21 27 implementation 28 29 function DelTree(DirName : string): Boolean; 30 var 31 SHFileOpStruct : TSHFileOpStruct; 32 DirBuf : array [0..255] of char; 33 begin 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; 51 end; 22 52 23 53 function BCDToInt(Value: Byte): Byte; … … 32 62 Path: array[0..MAX_PATH] of Char; 33 63 begin 64 Result := 'C:\Test'; 34 65 if SUCCEEDED(SHGetFolderPath(0, Folder, 0, SHGFP_TYPE_CURRENT, @path[0])) then 35 66 Result := path … … 133 164 end; 134 165 166 function GetBit(Variable:QWord;Index:Byte):Boolean; 167 begin 168 Result := ((Variable shr Index) and 1) = 1; 169 end; 170 171 procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload; 172 begin 173 Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index); 174 end; 175 176 procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload; 177 begin 178 Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index); 179 end; 180 181 procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload; 182 begin 183 Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index); 184 end; 185 186 function AddLeadingZeroes(const aNumber, Length : integer) : string; 187 begin 188 Result := SysUtils.Format('%.*d', [Length, aNumber]) ; 189 end; 190 135 191 end.
Note:
See TracChangeset
for help on using the changeset viewer.