- Timestamp:
- Oct 11, 2016, 4:23:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UCommon.pas
r489 r490 65 65 procedure FreeThenNil(var Obj); 66 66 function RemoveQuotes(Text: string): string; 67 function ComputerName: string; 68 function OccurenceOfChar(What: Char; Where: string): Integer; 69 function GetDirCount(Dir: string): Integer; 70 function MergeArray(A, B: array of string): TArrayOfString; 67 71 68 72 … … 287 291 L: LongWord; 288 292 begin 289 290 293 L := MAX_USERNAME_LENGTH + 2; 291 294 SetLength(Result, L); … … 302 305 end; 303 306 end; 307 308 function ComputerName: string; 309 {$ifdef mswindows} 310 const 311 INFO_BUFFER_SIZE = 32767; 312 var 313 Buffer : array[0..INFO_BUFFER_SIZE] of WideChar; 314 Ret : DWORD; 315 begin 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; 323 end; 324 {$endif} 325 {$ifdef unix} 326 begin 327 Result := GetHostName; 328 end; 329 {$endif} 304 330 305 331 function LoggedOnUserNameEx(Format: TUserNameFormat): string; … … 448 474 end; 449 475 476 function OccurenceOfChar(What: Char; Where: string): Integer; 477 var 478 I: Integer; 479 begin 480 Result := 0; 481 for I := 1 to Length(Where) do 482 if Where[I] = What then Inc(Result); 483 end; 484 485 function GetDirCount(Dir: string): Integer; 486 begin 487 Result := OccurenceOfChar(DirectorySeparator, Dir); 488 if Copy(Dir, Length(Dir), 1) = DirectorySeparator then 489 Dec(Result); 490 end; 491 492 function MergeArray(A, B: array of string): TArrayOfString; 493 var 494 I: Integer; 495 begin 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]; 501 end; 502 503 450 504 451 505 initialization
Note:
See TracChangeset
for help on using the changeset viewer.