Article # 308, added by Geoworks, historical record
| first | previous | index | next | last |

Checking for error in MSG_GEN_DOCUMENT_OPEN.



Q. I have a text editor and when I try to open the GEOS.INI file
   an error dialog appears saying I can't open the file. This I
   understand, but later on the program crashes when I try to
   exit.

A. The problem is in the GenDocument object that is created for the
   GEOS.INI file. Even though a message appears saying you can't
   open the file, a GenDocument object was created for it, and
   unfortunately, it remains in memory, uninitialized, waiting to
   cause an error later on. To solve this, in your
   MSG_GEN_DOCUMENT_OPEN handler check for an error returned by the
   superclass, then remove the GenDocument object.
   Here is a sample:

@method ZTEDocumentClass, MSG_GEN_DOCUMENT_OPEN {
    word * error;   /* Error value from ReadDataFromFile. */
    optr   ourText; /* Pointer to current text object. */

      /*
       * Check if error occurred during open.
       * If so, cancel the open. Return error status.
       * (Don't try to do MSG_GEN_DESTROY, that gives an error.)
       */
    if ( @callsuper() ) {
        @send self::MSG_GEN_REMOVE( VUM_NOW, 0 );
        return( TRUE );
    }
    else {
          /*
           * Read in text file by calling read data function.
           * Prepare necessary parameters first.
           */
        pself = ObjDerefGen( oself );
        ourText = ConstructOptr( pself->ZTEDI_textHandle,
                                 OptrToChunk( @ZTEText) );
        if ( ReadDataFromFile( pself->GDI_fileHandle, ourText, error ) ) {
            *fileOrError = *error;
            return( TRUE );
        }
        else {
            return( FALSE );
        }
    }
} /* MSG_GEN_DOCUMENT_OPEN */