Changeset 245 for Common/UCommon.pas
- Timestamp:
- May 23, 2011, 10:59:04 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UCommon.pas
r240 r245 1 1 unit UCommon; 2 2 3 {$mode delphi} 4 3 5 interface 4 6 5 7 uses 6 Windows, Classes, SysUtils, SpecializedList, StrUtils, Dialogs; //, ShFolder, ShellAPI; 8 Windows, Classes, SysUtils, SpecializedList, StrUtils, Dialogs, 9 FileUtil; //, ShFolder, ShellAPI; 7 10 8 11 type … … 25 28 var 26 29 ExceptionHandler: TExceptionEvent; 30 DLLHandle1: HModule; 31 GetUserNameEx: procedure (NameFormat: DWORD; 32 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 33 27 34 28 35 function IntToBin(Data: Cardinal; Count: Byte): string; … … 45 52 function GetFileFilterItemExt(Filter: string; Index: Integer): string; 46 53 procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog); 54 procedure DeleteFiles(APath, AFileSpec: string); 47 55 48 56 49 57 implementation 58 59 procedure DeleteFiles(APath, AFileSpec: string); 60 var 61 SearchRec: TSearchRec; 62 Find: Integer; 63 Path: string; 64 begin 65 Path := IncludeTrailingPathDelimiter(APath); 66 67 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 68 while Find = 0 do begin 69 DeleteFile(Path + SearchRec.Name); 70 71 Find := SysUtils.FindNext(SearchRec); 72 end; 73 FindClose(SearchRec); 74 end; 75 50 76 51 77 function GetFileFilterItemExt(Filter: string; Index: Integer): string; … … 226 252 end; 227 253 228 procedure GetUserNameEx(NameFormat: DWORD; 229 lpNameBuffer: LPSTR; nSize: PULONG); stdcall; 230 external 'secur32.dll' Name 'GetUserNameExA'; 231 254 function GetVersionInfo: TOSVersionInfo; 255 begin 256 Result.dwOSVersionInfoSize := SizeOf(Result); 257 if GetVersionEx(Result) then begin 258 end; 259 end; 232 260 233 261 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 234 262 var 235 263 UserName: array[0..250] of Char; 264 VersionInfo: TOSVersionInfo; 236 265 Size: DWORD; 237 266 begin 238 Size := 250; 239 GetUserNameEx(Integer(Format), @UserName, @Size); 240 Result := UTF8Encode(UserName); 267 VersionInfo := GetVersionInfo; 268 if VersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then begin 269 Size := 250; 270 GetUserNameEx(Integer(Format), @UserName, @Size); 271 Result := UTF8Encode(UserName); 272 end else Result := GetUserName; 241 273 end; 242 274 … … 272 304 end; 273 305 306 procedure LoadLibraries; 307 begin 308 DLLHandle1 := LoadLibrary('secur32.dll'); 309 if DLLHandle1 <> 0 then 310 begin 311 @GetUserNameEx := GetProcAddress(DLLHandle1, 'GetUserNameExA'); 312 end; 313 end; 314 315 procedure FreeLibraries; 316 begin 317 if DLLHandle1 <> 0 then FreeLibrary(DLLHandle1); 318 end; 319 320 321 initialization 322 323 LoadLibraries; 324 325 326 finalization 327 328 FreeLibraries; 329 274 330 end.
Note:
See TracChangeset
for help on using the changeset viewer.