Cmd字符串到delphi中的PAnsiChar

mad*_*550 1 delphi string delphi-7

我是Delphi的新手,我想使用ShellExecute命令快速创建一个应用程序。

我想在编辑框中使用字符串值添加到命令行以在应用程序外部执行处理作业。

一切正常,但出现错误:

“不兼容的类型:字符串和PAnsiChar”

我尝试使用:将其转换 Variable := PAnsiChar(AnsiString(editbox.Text),但无济于事。

任何人都可以帮助我解决这个问题。

Ken*_*ite 5

在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)

  • @ maddog550:我对此无能为力,因为您是a)没有提供您正在使用的实际代码,并且b)您没有在与该代码相关的上下文中向我们提供错误消息。如果您需要帮助,请[问题]编辑以提供引起问题的“精确代码”(包括变量声明),您所看到的“确切错误消息”(包括识别引起该问题的行) )。我们只能根据您提供的信息提供帮助,这就是我们所做的。您需要更多帮助吗?提供更多详细信息。 (2认同)