Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

October 24, 2007

Check for NULL, null, Nothing, nil, None

Note: Any Chilkat method that returns a reference to an object will return a NULL reference upon failure. You should always check for NULL before dereferencing the object (i.e. before trying to use it).

Here are examples in various programming languages for the mailman.CopyMail method (which downloads email from a POP3 server and returns an EmailBundle object):

C#:

Chilkat.EmailBundle bundle = null;
bundle = mailman.CopyMail();
if (bundle == null ) {
    MessageBox.Show(mailman.LastErrorText);
    return;
}

VB.NET:

Dim bundle As Chilkat.EmailBundle
bundle = mailman.CopyMail()
If (bundle Is Nothing ) Then
    MsgBox(mailman.LastErrorText)
    Exit Sub
End If

C++:

    CkEmailBundle *bundle = 0;
    bundle = mailman.CopyMail();
    if (bundle == 0 ) {
        printf("%s\n",mailman.lastErrorText());
        return;
    }

VB6:

Dim bundle As ChilkatEmailBundle2
Set bundle = mailman.CopyMail()
If (bundle Is Nothing ) Then
    MsgBox mailman.LastErrorText
    Exit Sub
End If

Delphi:

bundle := mailman.CopyMail();
if (bundle = nil ) then
  begin
    ShowMessage(mailman.LastErrorText);
  end;

Foxpro:

loBundle = loMailman.CopyMail()
IF (loBundle = NULL ) THEN
    =MESSAGEBOX(loMailman.LastErrorText)
    QUIT
ENDIF

SQL Server Stored Procedure:

    DECLARE @bundle int
	
    EXEC sp_OAMethod @mailman, 'CopyMail', @bundle OUT
    IF @bundle Is NULL
      BEGIN
        EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

Ruby:

bundle = mailman.CopyMail()
if (bundle == nil )
    print mailman.lastErrorText() + "\n"
    exit
end

Perl:

$bundle = $mailman->CopyMail();
if ($bundle eq null ) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

Python:

bundle = mailman.CopyMail()
if (bundle == None ):
    print mailman.lastErrorText()
    sys.exit()

Java:

    CkEmailBundle bundle;
    bundle = mailman.CopyMail();
    if (bundle == null ) {
        System.out.println(mailman.lastErrorText());
        return;
    }

Classic ASP:

Set bundle = mailman.CopyMail()
If (bundle Is Nothing ) Then
    Response.Write mailman.LastErrorText & ""
End If


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.