How to open an external file to Delphi



  • A button was to be built into the program, leading to an external echo. Got it. The buoyant Path, which I first laid down the current path:

    Path:=extractfilepath(paramstr(0));
    

    With this variable, my browser turned between pages.

    if Node.StateIndex = 8 then
    WebBrowser1.Navigate(Path+'kek\l5.htm');
    

    But when I do the same to that external echo, it doesn't work anymore. Now I'm opening an external file to press the button:

    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    ShellExecute(handle,'open','C:\Users\Пользователь1\Desktop\kekek\test.exe',nil,nil,SW_SHOW);
    end;
    

    It only works if I write the whole way, which naturally doesn't work. If I do this:

    ShellExecute(handle,'open',Path+'test.exe',nil,nil,SW_SHOW);
    

    There's a mistake [Error] Unit1.pas(292): Incompatible types: 'String' and 'PAnsiChar'.

    Please tell me how to fix this code or some other way to open the external file.



  • This WinApi function is used as a parameter by a line indicator and for literals, the compiler is responsible for installing itself.

    But since in this case, it's not a literal line, it needs to be led to the right type by hand.

    PChar(Path+'test.exe')
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2