CDO Emulation of VBasic value NOTHING (Views: 29)
Problem/Question/Abstract: 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. // =================================== // 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; end; For more information on CDO see CDO.HLP (From MS-Exchange CD) or Web Site http://www.cdolive.com/exchange2000.htm |