Reputation: 45
I am relatively new to Delphi and I want to make a quick application the uses the ShellExecute
command.
I want to use string values in edit boxes to add to the command line for doing the processing job outside of the application.
Everything works fine, but I get the error :
"Incompatible types: String and PAnsiChar"
I have tried to convert it using:
Variable := PAnsiChar(AnsiString(editbox.Text)
, but to no avail.
Can anyone assist me with this problem please.
Upvotes: 2
Views: 8623
Reputation: 125640
In Delphi 7, it's a simple typecast to PChar
, which is already a PAnsiChar
:
PChar(YourStringVariable);
or
PChar('Some text here'); // Cast not needed; demonstration only
PChar('C:\' + AFileName); // Cast needed because of variable use
Using it with ShellExecute
:
AFile := 'C:\MyDir\Readme.txt';
Res := ShellExecute(0, 'open', PChar(AFile),
nil, nil, SW_NORMAL )
Upvotes: 5
Reputation: 28517
How could it work fine when you cannot compile it?
You have posted too little code to be sure what is wrong, but you definitively have one typecast too much. AnsiChar
is type that can store only single character and it makes no sense here.
If Variable
is PAnsiChar
then you should be using:
Variable := PAnsiChar(editbox.Text)
Upvotes: 2