Re: Prob with Delphi ShellExecute

Posted by Roger on August 31, 2005

In Reply to: Another prob with Delphi ShellExecute posted by Andrew on August 30, 2005

: I'm having a problem with this:
: ShellExecute(Form1.Handle,nil,TString,nil,nil,SW_SHOWMAXIMIZED)
: where TString is a variable string.
: Is there a way of having Delphi's ShellExecute with that variable? The Error i'm getting is: incompatible Types (String and PAnsiChar).

If SProg is a string variable, that contains the path to a program, such as:

SProg := 'c:\windows\calc.exe';

then you can use it in a ShellExecute as follows:

ShellExecute(Handle, 'open', PChar(SProg), nil, nil, SW_SHOWMAXIMIZED); 

For the syntax of Delphi's ShellExecute, have a look at the DelphiLand's tutorial "Running an external Application" in the section "Code Snips".

Related Articles and Replies

Running External Application
Tutorial: run an external program from within a Delphi program and even wait for its completion.