Changeset 167 for branches/generator/Packages/Common/UCommon.pas
- Timestamp:
- Aug 9, 2018, 3:43:27 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Packages/Common/UCommon.pas
r114 r167 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 = nil); 76 function GetStringPart(var Text: string; Separator: string): string; 77 function PosFromIndex(SubStr: string; Text: string; 78 StartIndex: Integer): Integer; 79 function PosFromIndexReverse(SubStr: string; Text: string; 80 StartIndex: Integer): Integer; 73 81 74 82 … … 112 120 Path := IncludeTrailingPathDelimiter(APath); 113 121 114 Find := FindFirst( UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);122 Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec); 115 123 while Find = 0 do begin 116 DeleteFile(Path + UTF8Encode(SearchRec.Name));124 DeleteFile(Path + SearchRec.Name); 117 125 118 126 Find := SysUtils.FindNext(SearchRec); … … 429 437 end; 430 438 431 procedure ExecuteProgram( CommandLine:string);439 procedure ExecuteProgram(Executable: string; Parameters: array of string); 432 440 var 433 441 Process: TProcess; 442 I: Integer; 434 443 begin 435 444 try 436 445 Process := TProcess.Create(nil); 437 Process.CommandLine := CommandLine; 446 Process.Executable := Executable; 447 for I := 0 to Length(Parameters) - 1 do 448 Process.Parameters.Add(Parameters[I]); 438 449 Process.Options := [poNoConsole]; 439 450 Process.Execute; … … 456 467 procedure OpenFileInShell(FileName: string); 457 468 begin 458 ExecuteProgram('cmd.exe /c start "' + FileName + '"');469 ExecuteProgram('cmd.exe', ['/c', 'start', FileName]); 459 470 end; 460 471 … … 511 522 end; 512 523 513 524 function DefaultSearchFilter(const FileName: string): Boolean; 525 begin 526 Result := True; 527 end; 528 529 procedure SearchFiles(AList: TStrings; Dir: string; 530 FilterMethod: TFilterMethodMethod = nil); 531 var 532 SR: TSearchRec; 533 begin 534 Dir := IncludeTrailingPathDelimiter(Dir); 535 if FindFirst(Dir + '*', faAnyFile, SR) = 0 then 536 try 537 repeat 538 if (SR.Name = '.') or (SR.Name = '..') or (Assigned(FilterMethod) and (not FilterMethod(SR.Name) or 539 not FilterMethod(Copy(Dir, 3, Length(Dir)) + SR.Name))) then Continue; 540 AList.Add(Dir + SR.Name); 541 if (SR.Attr and faDirectory) <> 0 then 542 SearchFiles(AList, Dir + SR.Name, FilterMethod); 543 until FindNext(SR) <> 0; 544 finally 545 FindClose(SR); 546 end; 547 end; 548 549 function GetStringPart(var Text: string; Separator: string): string; 550 var 551 P: Integer; 552 begin 553 P := Pos(Separator, Text); 554 if P > 0 then begin 555 Result := Copy(Text, 1, P - 1); 556 Delete(Text, 1, P - 1 + Length(Separator)); 557 end else begin 558 Result := Text; 559 Text := ''; 560 end; 561 Result := Trim(Result); 562 Text := Trim(Text); 563 end; 564 565 function PosFromIndex(SubStr: string; Text: string; 566 StartIndex: Integer): Integer; 567 var 568 I, MaxLen: SizeInt; 569 Ptr: PAnsiChar; 570 begin 571 Result := 0; 572 if (StartIndex < 1) or (StartIndex > Length(Text) - Length(SubStr)) then Exit; 573 if Length(SubStr) > 0 then begin 574 MaxLen := Length(Text) - Length(SubStr) + 1; 575 I := StartIndex; 576 Ptr := @Text[StartIndex]; 577 while (I <= MaxLen) do begin 578 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 579 Result := I; 580 Exit; 581 end; 582 Inc(I); 583 Inc(Ptr); 584 end; 585 end; 586 end; 587 588 function PosFromIndexReverse(SubStr: string; Text: string; 589 StartIndex: Integer): Integer; 590 var 591 I: SizeInt; 592 Ptr: PAnsiChar; 593 begin 594 Result := 0; 595 if (StartIndex < 1) or (StartIndex > Length(Text)) then Exit; 596 if Length(SubStr) > 0 then begin 597 I := StartIndex; 598 Ptr := @Text[StartIndex]; 599 while (I > 0) do begin 600 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 601 Result := I; 602 Exit; 603 end; 604 Dec(I); 605 Dec(Ptr); 606 end; 607 end; 608 end; 514 609 515 610 initialization
Note:
See TracChangeset
for help on using the changeset viewer.