删除文件到回收站操作,编译时出现这个对话框,不知道是不是系统和api不兼容的原因。请大家指教!
一个小程序,打开一个文件,然后将这个文件删除到回收站里。
Debugger Exception Notification
Project Project1.exe rased exception class
EAccessViolation with message 'Access violation at address
77EB00E9 in moudule 'kernel32.dll' , Read of address
12350012.Process stopped.Use Step or Run to continue.
ok help
代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
SHELLAPI;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
OpStruc:TSHFileOPStruct;
begin
with OpStruc do
begin
Wnd:=Form1.Handle;
wFunc:=FO_DELETE;
pFrom:=PChar(Edit1.Text);
fFlags:=FOF_ALLOWUNDO;
end;
SHFILEOPERATION(OpStruc);
end;
end.