Changeset 490


Ignore:
Timestamp:
Oct 11, 2016, 4:23:55 PM (8 years ago)
Author:
chronos
Message:
  • Added: Various new functions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r489 r490  
    6565procedure FreeThenNil(var Obj);
    6666function RemoveQuotes(Text: string): string;
     67function ComputerName: string;
     68function OccurenceOfChar(What: Char; Where: string): Integer;
     69function GetDirCount(Dir: string): Integer;
     70function MergeArray(A, B: array of string): TArrayOfString;
    6771
    6872
     
    287291  L: LongWord;
    288292begin
    289 
    290293  L := MAX_USERNAME_LENGTH + 2;
    291294  SetLength(Result, L);
     
    302305  end;
    303306end;
     307
     308function ComputerName: string;
     309{$ifdef mswindows}
     310const
     311 INFO_BUFFER_SIZE = 32767;
     312var
     313  Buffer : array[0..INFO_BUFFER_SIZE] of WideChar;
     314  Ret : DWORD;
     315begin
     316  Ret := INFO_BUFFER_SIZE;
     317  If (GetComputerNameW(@Buffer[0],Ret)) then begin
     318    Result := UTF8Encode(WideString(Buffer));
     319  end
     320  else begin
     321    Result := 'ERROR_NO_COMPUTERNAME_RETURNED';
     322  end;
     323end;
     324{$endif}
     325{$ifdef unix}
     326begin
     327  Result := GetHostName;
     328end;
     329{$endif}
    304330
    305331function LoggedOnUserNameEx(Format: TUserNameFormat): string;
     
    448474end;
    449475
     476function OccurenceOfChar(What: Char; Where: string): Integer;
     477var
     478  I: Integer;
     479begin
     480  Result := 0;
     481  for I := 1 to Length(Where) do
     482    if Where[I] = What then Inc(Result);
     483end;
     484
     485function GetDirCount(Dir: string): Integer;
     486begin
     487  Result := OccurenceOfChar(DirectorySeparator, Dir);
     488  if Copy(Dir, Length(Dir), 1) = DirectorySeparator then
     489    Dec(Result);
     490end;
     491
     492function MergeArray(A, B: array of string): TArrayOfString;
     493var
     494  I: Integer;
     495begin
     496  SetLength(Result, Length(A) + Length(B));
     497  for I := 0 to Length(A) - 1 do
     498    Result[I] := A[I];
     499  for I := 0 to Length(B) - 1 do
     500    Result[Length(A) + I] := B[I];
     501end;
     502
     503
    450504
    451505initialization
Note: See TracChangeset for help on using the changeset viewer.