gpt4 book ai didi

delphi - E2010 不兼容类型 : 'string' and 'PWideChar'

转载 作者:行者123 更新时间:2023-12-03 03:48:18 25 4
gpt4 key购买 nike

因此,我尝试在 ShellExecute 中使用变量,但在编译时总是出现此错误[DCC Error] Unit1.pas(44): E2010 不兼容类型:'string' 和 'PWideChar'

我只有 2 个变量,它们都是字符串 ssidpass错误所在行为:ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan setHostednetwork ssid=' + ssid 'key=' + pass, nil, HIDE_WINDOW);

如果您现在已经注意到,我正在尝试制作一个使用 cmd 来设置、停止和启动热点的程序。如果我使用此行 ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan setHostednetwork ssid=VirtualRouter key=12345678', nil, HIDE_WINDOW); 它工作得很好。

项目代码:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, StdCtrls;

type
TSSID = class(TForm)
lblSSID: TLabel;
edtSSID: TEdit;
lblPASS: TLabel;
edtPASS: TEdit;
btnConfig: TButton;
btnStart: TButton;
btnRestart: TButton;
btnStop: TButton;
lblname: TLabel;
lblname2: TLabel;
procedure btnConfigClick(Sender: TObject);
procedure btnStartClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure btnRestartClick(Sender: TObject);
private
{ Private declarations }
public
ssid: String;
pass: String;
end;

var
SSID: TSSID;

implementation

{$R *.dfm}

procedure TSSID.btnConfigClick(Sender: TObject);
begin
ssid := edtSSID.Text;
pass := edtPASS.Text;
lblname2. Caption := edtSSID.Text;
ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan set hostednetwork ssid=' + ssid 'key=' + pass, nil, HIDE_WINDOW);
end;

procedure TSSID.btnRestartClick(Sender: TObject);
begin

ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan stop hostednetwork', nil, HIDE_WINDOW);
ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan start hostednetwork', nil, HIDE_WINDOW);

end;

procedure TSSID.btnStartClick(Sender: TObject);
begin

ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan start hostednetwork', nil, HIDE_WINDOW);

end;

procedure TSSID.btnStopClick(Sender: TObject);
begin

ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan stop hostednetwork', nil, HIDE_WINDOW);

end;

end.

有什么帮助吗?谢谢。是的,我是德尔福的新人,如果我想做的事情不起作用,我很抱歉

最佳答案

'/c netsh wlan set hostednetwork ssid=' + said 'key=' + pass

这缺少一个+,而你真正的意思是:

'/c netsh wlan set hostednetwork ssid=' + said + 'key=' + pass

此表达式的类型为字符串,但 ShellExecute 期望提供一个 PChar 类型的参数。将字符串转换为 PChar,如下所示:

PChar('/c netsh wlan set hostednetwork ssid=' + ssid + 'key=' + pass)

关于delphi - E2010 不兼容类型 : 'string' and 'PWideChar' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38900012/

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