Question

I create this menu using code placed by Sertac Akyuz in answer here: Show the default right-click menu - Delphi and it works good, but there is problem: When I click in created menu: delete (delete file to recycled) - it asks me: Are you sure want to delete?

When i click Yes - it works ok, but when I click no - it shows me an error, I see in debugger, error is on line:

OleCheck(ContextMenu.InvokeCommand(CommandInfo));

Error: ###(gdb unparsed remainder:s 0x0 out of bounds>)###.

I use Lazarus, but i think, that in Delphi it is actual too.

It seems to me, that the menu (windows) try to return to my program the answer - No, and in this situation error occurs.

How to solve this problem? How correct solve this situation with answer 'No'?

Was it helpful?

Solution

You haven't specified the error number, but when I tried to duplicate the steps, the OleCheck call failed with 0x80270000. The high word part, save the error bit, is 0x27 (39), that's FACILTY_SHELL as defined in 'winerror.h'. As you can see, the low word is '0', the shell does not give any specific error code, in fact the code is identical with ERROR_SUCCESS or NO_ERROR.

My interpretation is, the shell is just notifying that the command (the delete operation) failed. The fail is due to the user canceling the operation. My suggestion is, modify the code accordingly as you see fit. You have the knowledge that the operation failed, but you may choose to ignore it, or perhaps notify the user. Maybe something like this:

var
  ...
  InvokeResult: HRESULT;
begin

  ...
//      OleCheck(ContextMenu.InvokeCommand(CommandInfo));
      InvokeResult := ContextMenu.InvokeCommand(CommandInfo);
      if not Succeeded(InvokeResult) then begin
        if LoWord(InvokeResult) = NO_ERROR then
          ShowMessage('Command did not carried out')
        else
          OleError(InvokeResult);
      end;
    ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top