各位同行,现在我把一个Delphi小程序贴出来,
procedure TForm1.Button4Click(Sender: TObject);
var fStruct:TSHFileOpStruct;
begin
with fStruct do
begin
Wnd:=Handle;
wFunc:=FO_Delete;
pFrom:=pchar('E: emp'+#0#0);
fFlags:=FOF_AllowUndo;
end;
try
if ShFileOperation(fStruct)<>0 then showmessage('Delete Files Error!');
except
exit;
end;
end;
这段代码可以正常执行,但是以下的方式就有问题:
procedure DeleteFileDirectors(aHandle:THandle;sDirectory:String);
var fStruct:TSHFileOpStruct;
begin
with fStruct do
begin
Wnd:=aHandle;
wFunc:=FO_Delete;
pFrom:=pchar(sDirectory+#0#0);
fFlags:=FOF_AllowUndo;
end;
try
if ShFileOperation(fStruct)<>0 then showmessage('Delete Files Error!');
except
exit;
end;
end;
这段代码是放在一个自编的公共函数,过程的单元uPublic.pas.
都有USES ShellAPI,在Form1的单元也有USES uPublic
窗体调用该过程会出错,请问这有什么不当的地方?