IFileOperation and moving file to trash lazarus / 34-Windows ---------------------------------------------------------------------- devers000 · 2018-04-22 08:02 Hi there! Have problem with moving file to trash. At first I tried to work with SHFileOperation Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.remove_to_trash(aFile : PChar):integer;var  fileOpStruct : TSHFILEOPSTRUCT;begin  fileOpStruct.wnd:=0;  fileOpStruct.wFunc := FO_DELETE;  fileOpStruct.pFrom := aFile;  fileOpStruct.fFlags := FOF_ALLOWUNDO + FOF_NOCONFIRMATION;  Result := SHFileOperation(fileOpStruct);end; //callingerr_code := remove_to_trash(PChar(str_file+#0))  And I got error 124 if str_file contains cyrillic symbols. I've read about IFileOperation interface and found example for Delphi but Lazarus doesn't support this interface. Could you please help me to solve this task - move file to trash. Thanks in advance. P.S. I use last version lazarus-1.8.2-fpc-3.0.4-win32, Windows 7 x64 Russian ---------------------------------------------------------------------- Thaddy · 2018-04-22 10:12 Quote from: devers000 on April 22, 2018, 10:02:08 ambut Lazarus doesn't support this interface. It does. Why do you think it doesn't? Maybe you need the widechar versions: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.remove_to_trash(aFile : PWideChar):integer;var  fileOpStruct : TSHFILEOPSTRUCTW;begin  fileOpStruct.wnd:=0; // note: Application.MainForm.Handle  fileOpStruct.wFunc := FO_DELETE;  fileOpStruct.pFrom := aFile;  fileOpStruct.fFlags := FOF_ALLOWUNDO + FOF_NOCONFIRMATION;  Result := SHFileOperationW(fileOpStruct);end;Note there is a slightly different version in the JEDI package. ---------------------------------------------------------------------- ASerge · 2018-04-22 13:02 Do not forget that pFrom is a list of paths separated by the symbol #0 and at the end additional #0 as the end of the list. ---------------------------------------------------------------------- Thaddy · 2018-04-22 14:20 Indeed #0 as separator and #0#0 as terminator. But I don't think that was the issue here, although it can be. Btw, I forgot to add that {$mode delphiunicode} will pick the W versions by default. And these are since NT2000 (maybe even NT4) always the real versions that are called. The AnsiString A versions are mostly stubs and redirect to the W versions anyway. ---------------------------------------------------------------------- devers000 · 2018-04-22 17:03 Thank you for response! I've tried to use the widechar versions but got error Quoteunit1.pas(79,42) Error: Incompatible type for arg no. 1: Got "_SHFILEOPSTRUCTW", expected "LPSHFILEOPSTRUCTW" Lazarus doesn't support this interface because I got error Quoteunit1.pas(61,11) Error: Identifier not found "IFileOperation" I've added Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ActiveX, ComObj, ShlObj;and I can't find "IFileOperation" inside Lazarus modules. ---------------------------------------------------------------------- ASerge · 2018-04-22 17:30 This work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ShellApi; function MoveToTrash(const FilePaths: UnicodeString): Boolean;var  R: TSHFILEOPSTRUCTW;begin  FillChar(R, SizeOf(R), 0);  R.wFunc := FO_DELETE;  R.pFrom := PWideChar(FilePaths + #0);  R.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;  Result := SHFileOperationW(@R) = 0;end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  if MoveToTrash('c:\temp\1.txt') then    Caption := 'Work!';end; ---------------------------------------------------------------------- devers000 · 2018-04-22 17:48 Thank you ASerge! Now I see where I was wrong and made error. I should use @ and UnicodeString type