Changeset 40 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- Dec 10, 2016, 11:01:49 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r12 r40 6 6 7 7 uses 8 {$IFDEF Windows}Windows,{$ENDIF} 8 {$ifdef Windows}Windows,{$endif} 9 {$ifdef Linux}baseunix,{$endif} 9 10 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 11 FileUtil; //, ShFolder, ShellAPI; … … 65 66 procedure FreeThenNil(var Obj); 66 67 function RemoveQuotes(Text: string): string; 68 function ComputerName: string; 69 function OccurenceOfChar(What: Char; Where: string): Integer; 70 function GetDirCount(Dir: string): Integer; 71 function MergeArray(A, B: array of string): TArrayOfString; 67 72 function LoadFileToStr(const FileName: TFileName): AnsiString; 68 73 … … 288 293 L: LongWord; 289 294 begin 290 291 295 L := MAX_USERNAME_LENGTH + 2; 292 296 SetLength(Result, L); … … 303 307 end; 304 308 end; 305 309 {$endif} 310 311 function ComputerName: string; 312 {$ifdef mswindows} 313 const 314 INFO_BUFFER_SIZE = 32767; 315 var 316 Buffer : array[0..INFO_BUFFER_SIZE] of WideChar; 317 Ret : DWORD; 318 begin 319 Ret := INFO_BUFFER_SIZE; 320 If (GetComputerNameW(@Buffer[0],Ret)) then begin 321 Result := UTF8Encode(WideString(Buffer)); 322 end 323 else begin 324 Result := 'ERROR_NO_COMPUTERNAME_RETURNED'; 325 end; 326 end; 327 {$endif} 328 {$ifdef unix} 329 var 330 Name: UtsName; 331 begin 332 fpuname(Name); 333 Result := Name.Nodename; 334 end; 335 {$endif} 336 337 {$ifdef windows} 306 338 function LoggedOnUserNameEx(Format: TUserNameFormat): string; 307 339 const … … 418 450 419 451 procedure OpenWebPage(URL: string); 420 var421 Process: TProcess;422 Browser, Params: string;423 452 begin 424 453 OpenURL(URL); 425 {try426 Process := TProcess.Create(nil);427 Browser := '';428 //FindDefaultBrowser(Browser, Params);429 //Process.Executable := Browser;430 //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);431 Process.CommandLine := 'cmd.exe /c start ' + URL;432 Process.Options := [poNoConsole];433 Process.Execute;434 finally435 Process.Free;436 end;}437 454 end; 438 455 … … 447 464 if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then 448 465 Result := Copy(Text, 2, Length(Text) - 2); 466 end; 467 468 function OccurenceOfChar(What: Char; Where: string): Integer; 469 var 470 I: Integer; 471 begin 472 Result := 0; 473 for I := 1 to Length(Where) do 474 if Where[I] = What then Inc(Result); 475 end; 476 477 function GetDirCount(Dir: string): Integer; 478 begin 479 Result := OccurenceOfChar(DirectorySeparator, Dir); 480 if Copy(Dir, Length(Dir), 1) = DirectorySeparator then 481 Dec(Result); 482 end; 483 484 function MergeArray(A, B: array of string): TArrayOfString; 485 var 486 I: Integer; 487 begin 488 SetLength(Result, Length(A) + Length(B)); 489 for I := 0 to Length(A) - 1 do 490 Result[I] := A[I]; 491 for I := 0 to Length(B) - 1 do 492 Result[Length(A) + I] := B[I]; 449 493 end; 450 494 … … 467 511 end; 468 512 513 514 469 515 initialization 470 516
Note:
See TracChangeset
for help on using the changeset viewer.