Changeset 15 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- Feb 27, 2018, 6:11:44 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r1 r15 28 28 unfDNSDomainName = 11); 29 29 30 TFilterMethodMethod = function (FileName: string): Boolean of object; 30 31 var 31 32 ExceptionHandler: TExceptionEvent; … … 63 64 procedure OpenWebPage(URL: string); 64 65 procedure OpenFileInShell(FileName: string); 65 procedure ExecuteProgram( CommandLine:string);66 procedure ExecuteProgram(Executable: string; Parameters: array of string); 66 67 procedure FreeThenNil(var Obj); 67 68 function RemoveQuotes(Text: string): string; … … 70 71 function GetDirCount(Dir: string): Integer; 71 72 function MergeArray(A, B: array of string): TArrayOfString; 73 function LoadFileToStr(const FileName: TFileName): AnsiString; 74 procedure SearchFiles(AList: TStrings; Dir: string; 75 FilterMethod: TFilterMethodMethod); 72 76 73 77 … … 111 115 Path := IncludeTrailingPathDelimiter(APath); 112 116 113 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);117 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 114 118 while Find = 0 do begin 115 DeleteFile(Path + UTF8Encode(SearchRec.Name));119 DeleteFile(Path + SearchRec.Name); 116 120 117 121 Find := SysUtils.FindNext(SearchRec); … … 428 432 end; 429 433 430 procedure ExecuteProgram( CommandLine:string);434 procedure ExecuteProgram(Executable: string; Parameters: array of string); 431 435 var 432 436 Process: TProcess; 437 I: Integer; 433 438 begin 434 439 try 435 440 Process := TProcess.Create(nil); 436 Process.CommandLine := CommandLine; 441 Process.Executable := Executable; 442 for I := 0 to Length(Parameters) - 1 do 443 Process.Parameters.Add(Parameters[I]); 437 444 Process.Options := [poNoConsole]; 438 445 Process.Execute; … … 455 462 procedure OpenFileInShell(FileName: string); 456 463 begin 457 ExecuteProgram('cmd.exe /c start "' + FileName + '"');464 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 458 465 end; 459 466 … … 492 499 end; 493 500 501 function LoadFileToStr(const FileName: TFileName): AnsiString; 502 var 503 FileStream: TFileStream; 504 Read: Integer; 505 begin 506 Result := ''; 507 FileStream := TFileStream.Create(FileName, fmOpenRead); 508 try 509 if FileStream.Size > 0 then begin 510 SetLength(Result, FileStream.Size); 511 Read := FileStream.Read(Pointer(Result)^, FileStream.Size); 512 SetLength(Result, Read); 513 end; 514 finally 515 FileStream.Free; 516 end; 517 end; 518 519 function DefaultSearchFilter(const FileName: string): Boolean; 520 begin 521 Result := True; 522 end; 523 524 procedure SearchFiles(AList: TStrings; Dir: string; 525 FilterMethod: TFilterMethodMethod); 526 var 527 SR: TSearchRec; 528 begin 529 Dir := IncludeTrailingPathDelimiter(Dir); 530 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 531 try 532 repeat 533 if (SR.Name = '.') or (SR.Name = '..') or not FilterMethod(SR.Name) then Continue; 534 AList.Add(Dir + SR.Name); 535 if (SR.Attr and faDirectory) <> 0 then 536 SearchFiles(AList, Dir + SR.Name, FilterMethod); 537 until FindNext(SR) <> 0; 538 finally 539 FindClose(SR); 540 end; 541 end; 494 542 495 543
Note:
See TracChangeset
for help on using the changeset viewer.