Explorer BeforeItemPaste Event

Add-in Express™ Support Service
That's what is more important than anything else

Explorer BeforeItemPaste Event
How to use the BeforeItemPaste Event 
Andrew Lockwood




Posts: 50
Joined: 2014-12-29
I have trawled the internet but cannot find an answer to this.

If I copy a calendar item for example, I want to perform certain tasks on it before I paste it to the new folder. So I thought I could use the Explorer.BeforeItemPaste event. However, I cannot work out how to get the item.

I presume that I need to do something like Marshal.IsComObject(ClipboardContent) to check that that I am actually working with the Outlook Item.

However, my Delphi program does not recognise Marshal and I have no idea which unit it might be in.

So I suppose I have two questions:-

1) How do I use Marshal.IsComObject in Delphi
2) Is this the correct way to get the Outlook item?

Thanks,

Andrew
Posted 01 Oct, 2015 08:32:50 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Andrew,

Marshal.IsComObject belongs to the .NET world.

You need to check if the ClipboardContent parameter (it is of the OleVariant type) contains the Selection interface. If yes, then you can check all items in the Selection.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Oct, 2015 09:50:40 Top
Andrew Lockwood




Posts: 50
Joined: 2014-12-29
Thanks for the reply, but I do not understand it. Please could you show me how to do this? I have tried

ClipboardContent.QueryInterface(IID_Selection, Selection)

but I get the compiler error "Type not allowed in OLE automation call".

Thanks


Andrew
Posted 02 Oct, 2015 18:27:16 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Andrew,

var
  IDisp: IDispatch;
  ISelection: Selection;
begin
  if TVarData(ClipboardContent).VType = varDispatch then begin
    IDisp := IDispatch(ClipboardContent);
    if (Assigned(IDisp)) then begin
      ISelection := IDisp as Selection;
      if Assigned(ISelection) then begin
        // your stuff here
      end;
    end;
  end;
end;


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Oct, 2015 05:42:10 Top
Andrew Lockwood




Posts: 50
Joined: 2014-12-29
Andrei

Thanks for the code snippet. It starts to make some sense, but it does not work!

In my program, TVarData(ClipboardContent).VType = varByRef, not varDispatch, so the rest of the code inside the loop is never processed.

I have tried using FindVarData to get to the actual data in ClipboardContent as follows:-

ByRefData := (FindVarData(ClipboardContent));
VarData := ByRefData^

There seems to be some information in VarData, but I cannot work out what to do with it.

As I said at the outset, what I want to do is to modify the properties of the copy of the original Outlook Item before pasting it to the new location.

I am assuming that ClipboardContent holds the copy of the Outlook item - is that correct? If so, can you show me the missing links to get at the actual Outlook Item (at the moment, I am working with an AppointmentItem, but I would like to be able to handle different item types.

Thanks


Andrew
Posted 05 Oct, 2015 17:23:15 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Andrew,

This was a bug in the code of Add-in Express. In a minute, I'll send you a source code file containing the fix. You'll need to use it along with other Add-in Express source files.

The code I posted earlier works okay with the fix.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Oct, 2015 04:18:48 Top
Andrew Lockwood




Posts: 50
Joined: 2014-12-29
Brilliant!

Thanks for that. It is working properly now.


Andrew
Posted 06 Oct, 2015 18:41:14 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
You are welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Oct, 2015 01:17:00 Top