The program should have been embedded button leading to an external exe-shnik. There is a string variable Path, to which I assigned the current path at the beginning:

Path:=extractfilepath(paramstr(0)); 

With this variable, my browser switched between pages.

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

But when I do the same with that external exe-schnick, then it no longer works. Here I open the external file at the click of a button:

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

This only works if I write the full path, which of course is no good. If I do this:

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

Then the error [Error] Unit1.pas (292): Incompatible types: 'String' and 'PAnsiChar' appears.

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

  • try PChar(Path+'test.exe') - Grundy
  • @Grundy thanks a lot! - Vladimir
  • @Grundy Please post your comment as a response. - Nicolas Chabanovsky

1 answer 1

This WinApi function accepts a pointer to a string as a parameter, and for string literals, the compiler deals with the cast itself.

But since in this case, it is not the string literal that is passed, you need to manually cast it to the desired type.

 PChar(Path+'test.exe')