I try to compress files using winrar
command line,
But when I add a variable in the command line I get these error
Incompatible types 'PWideChar' and 'string' !
I convert the sdate variable to WideChar but it's not work !!
How I can fix it !
procedure TForm1.Button1Click(Sender: TObject);
var
mydate : TDateTime;
sdate : string;
begin
mydate:= Now-7;
sdate := FormatDateTime('YYYY/mm/dd',mydate);
ShellExecute(0, 'open', PChar('C:\Program Files\WinRAR\WinRar.exe'),
'a -r -ta'+ PChar(sdate) +' D:\xlsFiles.rar D:\*.xls*', nil, SW_SHOW);
end;
The text arguments of ShellExecute
are of type PChar
. But you supply a string for argument number 4.
The error message is very clear. You know by inspecting the declaration of ShellExecute
that the problematic argument is of type PChar
(an alias to PWideChar
). And the error message tells you that you are passing a string
.
Instead of
'a -r -ta'+ PChar(sdate) +' D:\xlsFiles.rar D:\*.xls*'
pass
PChar('a -r -ta'+ sdate +' D:\xlsFiles.rar D:\*.xls*')