Mega Code Archive

 
Categories / Delphi / Examples
 

CDO Emulation of VBasic value NOTHING

Title: CDO Emulation of VBasic value NOTHING Question: 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. 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. What is it then ..... The following 2 functions will emulate the behaviour of VB's NOTHING in Delphi. Answer: // =================================== // Emulate VB function IS NOTHING // =================================== function IsNothing(Obj : OleVariant) : boolean; begin Result := IDispatch(Obj) = nil; end; // ============================================ // Emulate VB function VarX := Nothing // ============================================ function varNothing : IDispatch; var Retvar : IDispatch; begin Retvar := nil; Result := Retvar; end; -------------------------------------------------------------------------- Now the VBasic example can translate to ... var objFolder,objMessages : OleVariant; objFolder := objSession.GetFolder(strFolderID); if IsNothing(objFolder) then begin objMessages := varNothing; ShowMessage('Unable to retrieve folder with specified ID'); exit; Exit Function end; For more information on CDO see CDO.HLP (From MS-Exchange CD) or Web Site http://www.cdolive.com/exchange2000.htm