Ignore:
Timestamp:
Sep 6, 2012, 8:29:27 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Balíček ModularSystem namísto vlastní implementace.
  • Upraveno: Aktualizace balíčku Common.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UCommon.pas

    r84 r89  
    77uses
    88  {$IFDEF Windows}Windows,{$ENDIF}
    9   Classes, SysUtils, StrUtils, Dialogs, Process,
     9  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
    1010  FileUtil; //, ShFolder, ShellAPI;
    1111
     
    4545function BCDToInt(Value: Byte): Byte;
    4646function CompareByteArray(Data1, Data2: TArrayOfByte): Boolean;
    47 {$IFDEF Windows}
    4847function GetUserName: string;
    4948function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    50 {$ENDIF}
    5149function SplitString(var Text: string; Count: Word): string;
    5250function 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);
     51procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload;
     52procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload;
     53procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); overload;
    5654function AddLeadingZeroes(const aNumber, Length : integer) : string;
    5755function LastPos(const SubStr: String; const S: String): Integer;
     
    6159procedure DeleteFiles(APath, AFileSpec: string);
    6260procedure OpenWebPage(URL: string);
     61procedure OpenFileInShell(FileName: string);
     62procedure ExecuteProgram(CommandLine: string);
     63procedure FreeThenNil(var Obj);
    6364
    6465
     
    283284  L: LongWord;
    284285begin
     286
    285287  L := MAX_USERNAME_LENGTH + 2;
    286288  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 := '';
    290293end;
    291294
     
    314317  end else Result := GetUserName;
    315318end;
     319{$ELSE}
     320function GetUserName: string;
     321begin
     322  Result := '';
     323end;
     324
     325function LoggedOnUserNameEx(Format: TUserNameFormat): string;
     326begin
     327  Result := '';
     328end;
     329
    316330{$ENDIF}
    317331
     
    365379end;
    366380
     381procedure ExecuteProgram(CommandLine: string);
     382var
     383  Process: TProcess;
     384begin
     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;
     393end;
     394
     395procedure FreeThenNil(var Obj);
     396begin
     397  TObject(Obj).Free;
     398  TObject(Obj) := nil;
     399end;
     400
    367401procedure OpenWebPage(URL: string);
    368402var
     
    370404  Browser, Params: string;
    371405begin
    372   try
     406  OpenURL(URL);
     407  {try
    373408    Process := TProcess.Create(nil);
    374409    Browser := '';
     
    381416  finally
    382417    Process.Free;
    383   end;
    384 end;
    385 
     418  end;}
     419end;
     420
     421procedure OpenFileInShell(FileName: string);
     422begin
     423  ExecuteProgram('cmd.exe /c start "' + FileName + '"');
     424end;
    386425
    387426initialization
Note: See TracChangeset for help on using the changeset viewer.