Changeset 141


Ignore:
Timestamp:
Dec 10, 2016, 4:21:11 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 edited

Legend:

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

    r3 r141  
    66
    77uses
    8   {$IFDEF Windows}Windows,{$ENDIF}
     8  {$ifdef Windows}Windows,{$endif}
     9  {$ifdef Linux}baseunix,{$endif}
    910  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
    1011  FileUtil; //, ShFolder, ShellAPI;
     
    6566procedure FreeThenNil(var Obj);
    6667function RemoveQuotes(Text: string): string;
     68function ComputerName: string;
     69function OccurenceOfChar(What: Char; Where: string): Integer;
     70function GetDirCount(Dir: string): Integer;
     71function MergeArray(A, B: array of string): TArrayOfString;
    6772
    6873
     
    287292  L: LongWord;
    288293begin
    289 
    290294  L := MAX_USERNAME_LENGTH + 2;
    291295  SetLength(Result, L);
     
    302306  end;
    303307end;
    304 
     308{$endif}
     309
     310function ComputerName: string;
     311{$ifdef mswindows}
     312const
     313 INFO_BUFFER_SIZE = 32767;
     314var
     315  Buffer : array[0..INFO_BUFFER_SIZE] of WideChar;
     316  Ret : DWORD;
     317begin
     318  Ret := INFO_BUFFER_SIZE;
     319  If (GetComputerNameW(@Buffer[0],Ret)) then begin
     320    Result := UTF8Encode(WideString(Buffer));
     321  end
     322  else begin
     323    Result := 'ERROR_NO_COMPUTERNAME_RETURNED';
     324  end;
     325end;
     326{$endif}
     327{$ifdef unix}
     328var
     329  Name: UtsName;
     330begin
     331  fpuname(Name);
     332  Result := Name.Nodename;
     333end;
     334{$endif}
     335
     336{$ifdef windows}
    305337function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    306338const
     
    417449
    418450procedure OpenWebPage(URL: string);
    419 var
    420   Process: TProcess;
    421   Browser, Params: string;
    422451begin
    423452  OpenURL(URL);
    424   {try
    425     Process := TProcess.Create(nil);
    426     Browser := '';
    427     //FindDefaultBrowser(Browser, Params);
    428     //Process.Executable := Browser;
    429     //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
    430     Process.CommandLine := 'cmd.exe /c start ' + URL;
    431     Process.Options := [poNoConsole];
    432     Process.Execute;
    433   finally
    434     Process.Free;
    435   end;}
    436453end;
    437454
     
    448465end;
    449466
     467function OccurenceOfChar(What: Char; Where: string): Integer;
     468var
     469  I: Integer;
     470begin
     471  Result := 0;
     472  for I := 1 to Length(Where) do
     473    if Where[I] = What then Inc(Result);
     474end;
     475
     476function GetDirCount(Dir: string): Integer;
     477begin
     478  Result := OccurenceOfChar(DirectorySeparator, Dir);
     479  if Copy(Dir, Length(Dir), 1) = DirectorySeparator then
     480    Dec(Result);
     481end;
     482
     483function MergeArray(A, B: array of string): TArrayOfString;
     484var
     485  I: Integer;
     486begin
     487  SetLength(Result, Length(A) + Length(B));
     488  for I := 0 to Length(A) - 1 do
     489    Result[I] := A[I];
     490  for I := 0 to Length(B) - 1 do
     491    Result[Length(A) + I] := B[I];
     492end;
     493
     494
    450495
    451496initialization
Note: See TracChangeset for help on using the changeset viewer.