Deleting files to the Recycle Bin

Unit : ShellAPI;

In the Delphi program, to delete a file we can also capitalize on the Recycle Bin that is by utilizing ShellAPI unit, so do not forget to declare the beginning of the program ShellAPI on Uses


example:
Create an Edit component, a OpenDialog and 2 Button. Perform double-clicking the Button1 component and button2, write the following program listing:

Uses ShellAPI;

procedure TF_DeleteFile.Button1Click(Sender: TObject);
begin
 if OpenDialog1.Execute then Edit1.Text:=OpenDialog1.FileName;
end;

procedure TF_DeleteRecycle.Button2Click(Sender: TObject);
var mOpStruct:TSHFileOpStruct;
    mFile    :string;
begin
 mFile:=Edit1.Text;
 with mOpStruct do begin
  Wnd    := Application.Handle; //handle kotak dialog
  wFunc  := FO_DELETE;          //operasi yg dilakukan
  pFrom  := PChar(mFile);       //path asal
  pTo    := nil;                //path tujuan
  fFlags := FOF_ALLOWUNDO;      //mempertahankan info undo (jika tersedia)
 end;
 SHFileOperation(mOpStruct);
end;

No comments:

Post a Comment