mad*_*550 1 delphi string delphi-7
我是Delphi的新手,我想使用ShellExecute
命令快速创建一个应用程序。
我想在编辑框中使用字符串值添加到命令行以在应用程序外部执行处理作业。
一切正常,但出现错误:
“不兼容的类型:字符串和PAnsiChar”
我尝试使用:将其转换
Variable := PAnsiChar(AnsiString(editbox.Text)
,但无济于事。
任何人都可以帮助我解决这个问题。
在Delphi 7中,这是一个简单的类型转换PChar
,已经是PAnsiChar
:
PChar(YourStringVariable);
Run Code Online (Sandbox Code Playgroud)
要么
PChar('Some text here'); // Cast not needed; demonstration only
PChar('C:\' + AFileName); // Cast needed because of variable use
Run Code Online (Sandbox Code Playgroud)
结合使用ShellExecute
:
AFile := 'C:\MyDir\Readme.txt';
Res := ShellExecute(0, 'open', PChar(AFile),
nil, nil, SW_NORMAL )
Run Code Online (Sandbox Code Playgroud)