Changeset 89 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- Sep 6, 2012, 8:29:27 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r84 r89 7 7 uses 8 8 {$IFDEF Windows}Windows,{$ENDIF} 9 Classes, SysUtils, StrUtils, Dialogs, Process, 9 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 10 FileUtil; //, ShFolder, ShellAPI; 11 11 … … 45 45 function BCDToInt(Value: Byte): Byte; 46 46 function CompareByteArray(Data1, Data2: TArrayOfByte): Boolean; 47 {$IFDEF Windows}48 47 function GetUserName: string; 49 48 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 50 {$ENDIF}51 49 function SplitString(var Text: string; Count: Word): string; 52 50 function GetBit(Variable: QWord; Index: Byte): Boolean; 53 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); 54 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); 55 procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); 51 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload; 52 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload; 53 procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); overload; 56 54 function AddLeadingZeroes(const aNumber, Length : integer) : string; 57 55 function LastPos(const SubStr: String; const S: String): Integer; … … 61 59 procedure DeleteFiles(APath, AFileSpec: string); 62 60 procedure OpenWebPage(URL: string); 61 procedure OpenFileInShell(FileName: string); 62 procedure ExecuteProgram(CommandLine: string); 63 procedure FreeThenNil(var Obj); 63 64 64 65 … … 283 284 L: LongWord; 284 285 begin 286 285 287 L := MAX_USERNAME_LENGTH + 2; 286 288 SetLength(Result, L); 287 if Windows.GetUserName(PChar(Result), L) and (L > 0) then 288 SetLength(Result, StrLen(PChar(Result))) else 289 Result := ''; 289 if Windows.GetUserName(PChar(Result), L) and (L > 0) then begin 290 SetLength(Result, StrLen(PChar(Result))); 291 Result := UTF8Encode(Result); 292 end else Result := ''; 290 293 end; 291 294 … … 314 317 end else Result := GetUserName; 315 318 end; 319 {$ELSE} 320 function GetUserName: string; 321 begin 322 Result := ''; 323 end; 324 325 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 326 begin 327 Result := ''; 328 end; 329 316 330 {$ENDIF} 317 331 … … 365 379 end; 366 380 381 procedure ExecuteProgram(CommandLine: string); 382 var 383 Process: TProcess; 384 begin 385 try 386 Process := TProcess.Create(nil); 387 Process.CommandLine := CommandLine; 388 Process.Options := [poNoConsole]; 389 Process.Execute; 390 finally 391 Process.Free; 392 end; 393 end; 394 395 procedure FreeThenNil(var Obj); 396 begin 397 TObject(Obj).Free; 398 TObject(Obj) := nil; 399 end; 400 367 401 procedure OpenWebPage(URL: string); 368 402 var … … 370 404 Browser, Params: string; 371 405 begin 372 try 406 OpenURL(URL); 407 {try 373 408 Process := TProcess.Create(nil); 374 409 Browser := ''; … … 381 416 finally 382 417 Process.Free; 383 end; 384 end; 385 418 end;} 419 end; 420 421 procedure OpenFileInShell(FileName: string); 422 begin 423 ExecuteProgram('cmd.exe /c start "' + FileName + '"'); 424 end; 386 425 387 426 initialization
Note:
See TracChangeset
for help on using the changeset viewer.