Changeset 192 for trunk/Packages/Common/UCommon.pas
- Timestamp:
- May 1, 2018, 10:18:03 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UCommon.pas
r116 r192 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); 76 function GetStringPart(var Text: string; Separator: string): string; 72 77 73 78 … … 111 116 Path := IncludeTrailingPathDelimiter(APath); 112 117 113 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);118 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 114 119 while Find = 0 do begin 115 DeleteFile(Path + UTF8Encode(SearchRec.Name));120 DeleteFile(Path + SearchRec.Name); 116 121 117 122 Find := SysUtils.FindNext(SearchRec); … … 428 433 end; 429 434 430 procedure ExecuteProgram( CommandLine:string);435 procedure ExecuteProgram(Executable: string; Parameters: array of string); 431 436 var 432 437 Process: TProcess; 438 I: Integer; 433 439 begin 434 440 try 435 441 Process := TProcess.Create(nil); 436 Process.CommandLine := CommandLine; 442 Process.Executable := Executable; 443 for I := 0 to Length(Parameters) - 1 do 444 Process.Parameters.Add(Parameters[I]); 437 445 Process.Options := [poNoConsole]; 438 446 Process.Execute; … … 455 463 procedure OpenFileInShell(FileName: string); 456 464 begin 457 ExecuteProgram('cmd.exe /c start "' + FileName + '"');465 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 458 466 end; 459 467 … … 492 500 end; 493 501 502 function LoadFileToStr(const FileName: TFileName): AnsiString; 503 var 504 FileStream: TFileStream; 505 Read: Integer; 506 begin 507 Result := ''; 508 FileStream := TFileStream.Create(FileName, fmOpenRead); 509 try 510 if FileStream.Size > 0 then begin 511 SetLength(Result, FileStream.Size); 512 Read := FileStream.Read(Pointer(Result)^, FileStream.Size); 513 SetLength(Result, Read); 514 end; 515 finally 516 FileStream.Free; 517 end; 518 end; 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 494 561 495 562
Note:
See TracChangeset
for help on using the changeset viewer.