Trapping RDO (Redemption) Events in Delphi

  • Thread starter Thread starter Andrew Lockwood
  • Start date Start date
A

Andrew Lockwood

Apologies for posting a question about Delphi, but I cannot find an active
Delphi forum for this type of issue.

Can anyone explain to me / show me some sample code for trapping the events
of an RDOMail item, for example. I have tried creating a wrapper as follows


TRDOMailItem = class(TOleServer)
private
FIntf : IRDOMail;
FOnModified : TNotifyEvent;
FOnDeleted : TNotifyEvent;
FOnMoved : TNotifyEvent;
FOnClose : TNotifyEvent;
function GetDefaultInterface: IRDOMail;
//FOnMovedEx : (const OldParentEntryId: WideString; const
NewParentEntryID: WideString); dispid 5;
protected
procedure Connect;
procedure ConnectTo(svrIntf : IRDOMail);
procedure Disconnect; override;
procedure InitServerData; override;
procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray);
override;
public
//need to add more events
property OnModified : TNotifyEvent read FOnModified write FOnModified;
property OnDeleted : TNotifyEvent read FOnDeleted write FOnDeleted;
property OnMoved : TNotifyEvent read FOnMoved write FOnMoved;
property OnClose : TNotifyEvent read FOnClose write FOnClose;
end;

procedure TRDOMailItem.InitServerData;
const
CServerData: TServerData = (
ClassID: '{02ABB20A-FB8A-4433-8D66-135C6CCD0F32}'; //Class_xxx
IntfIID: '{D85047E0-7767-4D48-86B6-28BDB5728ABB}'; //IID_xxx
EventIID: '{0D00E38E-315D-49D5-9331-80BC1559C0E7}'; //DIID_xxx
LicenseKey: nil;
Version: 500);

begin
ServerData := @CServerData;
end;

procedure TRDOOutlookServer.Connect;
var punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
ConnectEvents(punk);
Fintf:= punk;
end;
end;


but it doesn't work - it complies and runs OK, but the InvokeEvent procedure
is never executed, so I cannot capture the events.
 
Dmitry

Thanks for your reply - I really appreciate all your help.

What I want to do is to link to an item when it is received or sent.

So, for example, in the OnItemSend procedure, I have

procedure TADTAddIn.OnItemSend(Sender: TOutlookApplication; const Item:
IDispatch; var Cancel: WordBool)
begin
try
try
FCurrentItem := TRDOMailItem.Create(Item); // FCurrentItem is a
private TRDOMailItem of TADTAddIn
......
except
//oops...
end;

finally
end;
end;


unit uRDOOutlookTypes;

interface

uses ActiveX, Classes, OleServer, Redemption_TLB;

type
TRDOMailItem = class(TOleServer)
private
FOnModified : TNotifyEvent;
FOnDeleted : TNotifyEvent;
FOnMoved : TNotifyEvent;
FOnClose : TNotifyEvent;
FIntf : IUnknown;
function GetConnected: boolean;
protected
procedure InitServerData; override;
procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray);
override;
public
property OnModified : TNotifyEvent read FOnModified write FOnModified;
property OnDeleted : TNotifyEvent read FOnDeleted write FOnDeleted;
property OnMoved : TNotifyEvent read FOnMoved write FOnMoved;
property OnClose : TNotifyEvent read FOnClose write FOnClose;
constructor Create(svrIntf: IUnknown); reintroduce; virtual;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: IUnknown);
procedure Disconnect; override;
property Intf : IUnknown read FIntf;
property Connected : boolean read GetConnected;
end;

implementation

{ TRDOMailItem }

procedure TRDOMailItem.Connect;
var
punk: IUnknown;

begin
if FIntf = nil then
begin
punk := GetServer;
ConnectEvents(punk);
Fintf:= punk;
end;
end;


procedure TRDOMailItem.ConnectTo(svrIntf: IUnknown);
begin
Disconnect;
FIntf := svrIntf;
ConnectEvents(FIntf);
end;

constructor TRDOMailItem.Create(svrIntf: IUnknown);
begin
inherited Create(nil);
AutoConnect:=false;
ConnectKind:=ckAttachToInterface;
ConnectTo(svrIntf);
end;

destructor TRDOMailItem.Destroy;
begin
Disconnect;
inherited;
end;

procedure TRDOMailItem.Disconnect;
begin
if Fintf <> nil then
begin
DisconnectEvents(FIntf);
FIntf := nil;
end;
end;

function TRDOMailItem.GetConnected: boolean;
var CPC:IUnknown;
begin
Result:=(FIntf <> nil) and
Succeeded(FIntf.QueryInterface(IConnectionPointContainer, CPC))
end;

procedure TRDOMailItem.InitServerData;
const
CServerData: TServerData = (
ClassID: '{02ABB20A-FB8A-4433-8D66-135C6CCD0F32}'; //Class_xxx
IntfIID: '{D85047E0-7767-4D48-86B6-28BDB5728ABB}'; //IID_xxx
EventIID: '{0D00E38E-315D-49D5-9331-80BC1559C0E7}'; //DIID_xxx
LicenseKey: nil;
Version: 500);

begin
ServerData := @CServerData;
end;

procedure TRDOMailItem.InvokeEvent(DispID: TDispID; var Params:
TVariantArray);
var
Cancel : WordBool;

begin
case DispID of
-1:
Exit; // DISPID_UNKNOWN

1:
begin
if Assigned(FOnModified) then
FOnModified(Self);
end;
end;
end;
 
Dmitry
What is the rest of your code? When and how do you initialize RDOMail?

I posted answers to these questions on 27th October. If you could throw
some light on what I am doing wrong, I would be really grateful.


Andrew Lockwood
 
When a message is being sent, you should release all the references to it;
it now belongs to the spooler.
The message will be moved to the Outbox and, after it is successfully sent,
to the Sent Items folder.In bot hcases it will be a different message, nit
the one you had in the ItemSend event handler.
What exactly and why are you trying to do?


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Basically, I want to add a user property to the item denoting a category for
the email - normally a project number. I realise that I could do this by
creating a custom form and adding a drop down box or whatever to set the
category before clicking the send button.

But even if that is the better way to treat outgoing emails, I would still
like to understand how to use the RDOMail item object and to trap its
events - presumably I should be able to create an instance of an RDOMail
item in the OnSelectionChange procedure.


Andrew
 
Why do you need an event for that?
Why not simply add the property in the ItemSend event handler?
You should be able to set up an event sink on an RDOMail object in the
OnSelectionChange event handler. Again, how do you do that and why?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
What I am ultimately trying to do is to ensure that a user adds a project
number to all incoming and outgoing emails, and to prevent the user deleting
any emails that have a project number tag.

So I thought that I could prompt the user for the project number tag when
they send (OnItemSend) and when they read it (OnSelectionChange), and then
check that the tag is correctly set before they delete it (and prevent them
deleting it if it has a project number tag). So I was hoping that I could
use the OnDeleted event of RDOMail to achieve this.

I have just tried

procedure TADTAddIn.OnSelectionChange(Sender: TObject);
var
ItemSelected, SelectedItemChanged : boolean;
CurrentItem : OleVariant;

begin
CurrentItem := GetSelectedItem(GApplication);
FCurrentItem := TRDOMailItem.Create(CurrentItem); // FCurrentItem is a
private property of my AddIn
...
...
end;

in conjuction with my other code previously posted, but still nothing is
happening - the InvokeEvent
procedure is never executed.


Andrew
 
OnDeleted event will fire only *after* the message is deleted, so it will
not help you at all.
All MAPI events are asynchronous and fire only after the action has already
been completed.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Does that mean that the OnMoved event would fire when the item is moved to
the Deleted Items folder? If so, presumably I could achieve what I want by
trapping this event instead?


Andrew
 
Either that or Items.ItemAdd event on the Deleted Item folder.
*If* the message gets moved to the Deleted Items folder - I always use
Shift-Delete.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Thanks - sorry to be a bore, but does that not bring me back to my original
question - how do I trap the RDOMail events? I would have expected the code
I have already posted to work, but it doesn't.


Andrew
 
You would need the RDOItems.ItemAdd event, where RDOItems is retreived from
RDOFolder.Items collection, where RDOFolder points to the Deleted Items
folder.
This is the same as in the Outlook Obejc tModel.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Back
Top