Reputation: 317
So I am trying to use variables with ShellExecute but always get this error when compiling [DCC Error] Unit1.pas(44): E2010 Incompatible types: 'string' and 'PWideChar'
I only have 2 variables and they are both strings ssid
and pass
The line where the error is: ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan set hostednetwork ssid=' + ssid 'key=' + pass, nil, HIDE_WINDOW);
If you have noticed by now I am trying to make a program that uses cmd to set, stop and start a hotspot. If I use this line ShellExecute(0, nil, 'cmd.exe', '/c netsh wlan set hostednetwork ssid=VirtualRouter key=12345678', nil, HIDE_WINDOW);
it works just fine.
Projects code:
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.
Any help? Thx. and yes i am new at delphi so sorry if what i am trying to do wont work
Upvotes: 4
Views: 4295
Reputation: 612794
'/c netsh wlan set hostednetwork ssid=' + said 'key=' + pass
This misses a +
and you really meant:
'/c netsh wlan set hostednetwork ssid=' + said + 'key=' + pass
This expression is of type string, but ShellExecute
expects to be supplied an argument of type PChar
. Convert your string to PChar
like so:
PChar('/c netsh wlan set hostednetwork ssid=' + ssid + 'key=' + pass)
Upvotes: 3