所以我尝试在ShellExecute中使用变量,但在编译[DCC Error] Unit1.pas(44): E2010 Incompatible types: 'string' and 'PWideChar'
我只有2个变量,它们都是字符串ssid
和pass
错误所在的行:ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan set hostednetwork ssid=' + ssid 'key=' + pass, nil, HIDE_WINDOW);
如果您现在注意到我正在尝试制作一个使用cmd来设置,停止和启动热点的程序。如果我使用这一行ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan set hostednetwork 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.
有任何帮助吗?谢谢。是的,我是德尔福的新人,很抱歉,如果我想做什么不会工作
答案 0 :(得分:2)
'/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)