Changeset 73 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- Oct 27, 2016, 3:00:47 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r72 r73 8 8 {$IFDEF Windows}Windows,{$ENDIF} 9 9 Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf, 10 FileUtil , LazFileUtils; //, ShFolder, ShellAPI;10 FileUtil; //, ShFolder, ShellAPI; 11 11 12 12 type … … 64 64 procedure ExecuteProgram(CommandLine: string); 65 65 procedure FreeThenNil(var Obj); 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; 66 71 67 72 … … 91 96 I: Integer; 92 97 begin 93 Result := '';94 98 for I := 1 to Length(Source) do begin 95 99 Result := Result + LowerCase(IntToHex(Ord(Source[I]), 2)); … … 106 110 Path := IncludeTrailingPathDelimiter(APath); 107 111 108 Find := FindFirst( Path + AFileSpec, faAnyFile xor faDirectory, SearchRec);112 Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec); 109 113 while Find = 0 do begin 110 DeleteFile UTF8(Path + SearchRec.Name);114 DeleteFile(Path + UTF8Encode(SearchRec.Name)); 111 115 112 116 Find := SysUtils.FindNext(SearchRec); … … 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; … … 417 443 418 444 procedure OpenWebPage(URL: string); 445 var 446 Process: TProcess; 447 Browser, Params: string; 419 448 begin 420 449 OpenURL(URL); 450 {try 451 Process := TProcess.Create(nil); 452 Browser := ''; 453 //FindDefaultBrowser(Browser, Params); 454 //Process.Executable := Browser; 455 //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]); 456 Process.CommandLine := 'cmd.exe /c start ' + URL; 457 Process.Options := [poNoConsole]; 458 Process.Execute; 459 finally 460 Process.Free; 461 end;} 421 462 end; 422 463 … … 426 467 end; 427 468 469 function RemoveQuotes(Text: string): string; 470 begin 471 Result := Text; 472 if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then 473 Result := Copy(Text, 2, Length(Text) - 2); 474 end; 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 504 428 505 initialization 429 506
Note:
See TracChangeset
for help on using the changeset viewer.