Author: Mike Heydon
I am currently writing a class that encapsulates the CDO (Collaboration Data
Objects) in Delphi. For those of you who do not know what CDO is, it is a library
that allows acces to MS-Exchange and Outlook folders,messages etc. much in the way
of MAPI.
Answer:
One problem that kept cropping up from the examples in CDO.HLP was the use of
something called "NOTHING" in the VB examples.
eg.
Set objFolder = objSession.GetFolder(strFolderID)
If objFolder Is Nothing Then
Set objMessages = Nothing
MsgBox "Unable to retrieve folder with specified ID"
Exit Function
End If
This is not "VARNULL",'VAREMPTY" or even "UNASSIGNED" in Delphi. Trying "if
obFolder = VarNull" or any of above results in invalid typecast errors as do trying
to compare to NIL.
What is it then ..... It is an IDispatch type which is set to NIL
The following 2 functions will emulate the behaviour of VB's NOTHING in Delphi.
1 2 // ===================================3 // Emulate VB function IS NOTHING4 // ===================================5 6 function IsNothing(Obj: OleVariant): boolean;
7 begin8 Result := IDispatch(Obj) = nil;
9 end;
10 11 // ============================================12 // Emulate VB function VarX := Nothing13 // ============================================14 15 function varNothing: IDispatch;
16 var17 Retvar: IDispatch;
18 begin19 Retvar := nil;
20 Result := Retvar;
21 end;
22 23 --------------------------------------------------------------------------
24 Now the VBasic example can translate to ...
25 26 var27 objFolder, objMessages: OleVariant;
28 29 objFolder := objSession.GetFolder(strFolderID);
30 31 if IsNothing(objFolder) then32 begin33 objMessages := varNothing;
34 ShowMessage('Unable to retrieve folder with specified ID');
35 exit;
36 end;
For more information on CDO see CDO.HLP (From MS-Exchange CD) or Web Site
http://www.cdolive.com/exchange2000.htm