gpt4 book ai didi

string - 如何将字符串变量传递给需要 PChar 的函数?

转载 作者:行者123 更新时间:2023-12-03 14:50:35 26 4
gpt4 key购买 nike

我有这个代码:

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

最佳答案

我假设dirstring类型。然后

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com