我有这个代码:
ShellExecute(Handle, 'open',
'C:\Users\user\Desktop\sample\menu\WTSHELP\start.html',
nil, nil, sw_Show);
如何用字符串变量替换第三个参数中的文字?如果我使用如下代码,它将无法编译。
var
dir: string;
dir := 'C:\Users\user\Desktop\sample\menu\WTSHELP\start.html';
ShellExecute(Handle, 'open', dir, nil, nil, sw_Show);
最佳答案
我假设dir
是string
类型。然后
ShellExecute(Handle, 'open', PChar(dir), nil, nil, SW_SHOWNORMAL);
应该可以工作。事实上,编译器会告诉你这一点;它说的是类似的事情
[DCC Error] Unit1.pas(27): E2010 Incompatible types: 'string' and 'PWideChar'
(另请注意,当您调用 ShellExecute
时,您通常会使用 SW_SHOWNORMAL
。)
关于string - 如何将字符串变量传递给需要 PChar 的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15774302/