Changeset 38 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- May 10, 2018, 9:39:53 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r28 r38 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; … … 71 72 function MergeArray(A, B: array of string): TArrayOfString; 72 73 function LoadFileToStr(const FileName: TFileName): AnsiString; 74 procedure SearchFiles(AList: TStrings; Dir: string; 75 FilterMethod: TFilterMethodMethod); 76 function GetStringPart(var Text: string; Separator: string): string; 73 77 74 78 … … 112 116 Path := IncludeTrailingPathDelimiter(APath); 113 117 114 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);118 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 115 119 while Find = 0 do begin 116 DeleteFile(Path + UTF8Encode(SearchRec.Name));120 DeleteFile(Path + SearchRec.Name); 117 121 118 122 Find := SysUtils.FindNext(SearchRec); … … 429 433 end; 430 434 431 procedure ExecuteProgram( CommandLine:string);435 procedure ExecuteProgram(Executable: string; Parameters: array of string); 432 436 var 433 437 Process: TProcess; 438 I: Integer; 434 439 begin 435 440 try 436 441 Process := TProcess.Create(nil); 437 Process.CommandLine := CommandLine; 442 Process.Executable := Executable; 443 for I := 0 to Length(Parameters) - 1 do 444 Process.Parameters.Add(Parameters[I]); 438 445 Process.Options := [poNoConsole]; 439 446 Process.Execute; … … 456 463 procedure OpenFileInShell(FileName: string); 457 464 begin 458 ExecuteProgram('cmd.exe /c start "' + FileName + '"');465 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 459 466 end; 460 467 … … 511 518 end; 512 519 520 function DefaultSearchFilter(const FileName: string): Boolean; 521 begin 522 Result := True; 523 end; 524 525 procedure SearchFiles(AList: TStrings; Dir: string; 526 FilterMethod: TFilterMethodMethod); 527 var 528 SR: TSearchRec; 529 begin 530 Dir := IncludeTrailingPathDelimiter(Dir); 531 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 532 try 533 repeat 534 if (SR.Name = '.') or (SR.Name = '..') or not FilterMethod(SR.Name) or 535 not FilterMethod(Copy(Dir, 3, Length(Dir)) + SR.Name) then Continue; 536 AList.Add(Dir + SR.Name); 537 if (SR.Attr and faDirectory) <> 0 then 538 SearchFiles(AList, Dir + SR.Name, FilterMethod); 539 until FindNext(SR) <> 0; 540 finally 541 FindClose(SR); 542 end; 543 end; 544 545 function GetStringPart(var Text: string; Separator: string): string; 546 var 547 P: Integer; 548 begin 549 P := Pos(Separator, Text); 550 if P > 0 then begin 551 Result := Copy(Text, 1, P - 1); 552 Delete(Text, 1, P - 1 + Length(Separator)); 553 end else begin 554 Result := Text; 555 Text := ''; 556 end; 557 Result := Trim(Result); 558 Text := Trim(Text); 559 end; 560 513 561 514 562
Note:
See TracChangeset
for help on using the changeset viewer.