Ignore:
Timestamp:
Jan 22, 2018, 11:00:53 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UCommon.pas

    r141 r169  
    6363procedure OpenWebPage(URL: string);
    6464procedure OpenFileInShell(FileName: string);
    65 procedure ExecuteProgram(CommandLine: string);
     65procedure ExecuteProgram(Executable: string; Parameters: array of string);
    6666procedure FreeThenNil(var Obj);
    6767function RemoveQuotes(Text: string): string;
     
    7070function GetDirCount(Dir: string): Integer;
    7171function MergeArray(A, B: array of string): TArrayOfString;
     72function LoadFileToStr(const FileName: TFileName): AnsiString;
    7273
    7374
     
    111112  Path := IncludeTrailingPathDelimiter(APath);
    112113
    113   Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);
     114  Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec);
    114115  while Find = 0 do begin
    115     DeleteFile(Path + UTF8Encode(SearchRec.Name));
     116    DeleteFile(Path + SearchRec.Name);
    116117
    117118    Find := SysUtils.FindNext(SearchRec);
     
    428429end;
    429430
    430 procedure ExecuteProgram(CommandLine: string);
     431procedure ExecuteProgram(Executable: string; Parameters: array of string);
    431432var
    432433  Process: TProcess;
     434  I: Integer;
    433435begin
    434436  try
    435437    Process := TProcess.Create(nil);
    436     Process.CommandLine := CommandLine;
     438    Process.Executable := Executable;
     439    for I := 0 to Length(Parameters) - 1 do
     440      Process.Parameters.Add(Parameters[I]);
    437441    Process.Options := [poNoConsole];
    438442    Process.Execute;
     
    455459procedure OpenFileInShell(FileName: string);
    456460begin
    457   ExecuteProgram('cmd.exe /c start "' + FileName + '"');
     461  ExecuteProgram('cmd.exe', ['/c', 'start', FileName]);
    458462end;
    459463
     
    492496end;
    493497
     498function LoadFileToStr(const FileName: TFileName): AnsiString;
     499var
     500  FileStream: TFileStream;
     501  Read: Integer;
     502begin
     503  Result := '';
     504  FileStream := TFileStream.Create(FileName, fmOpenRead);
     505  try
     506    if FileStream.Size > 0 then begin
     507      SetLength(Result, FileStream.Size);
     508      Read := FileStream.Read(Pointer(Result)^, FileStream.Size);
     509      SetLength(Result, Read);
     510    end;
     511  finally
     512    FileStream.Free;
     513  end;
     514end;
     515
    494516
    495517
Note: See TracChangeset for help on using the changeset viewer.