Up   Previous   Next  

Disposing of a Text Object

When you close a window associated with a text object, you should call the TXNDeleteObject function to release the text object and all associated data structures from memory.

Listing 3-6 shows a sample function-- MyDisposeObject --that first checks the TXNGetChangeCount function to see if the text object has been modified since it was created or saved last. If it has been modified, you can give the user an opportunity to save the changes before the object is deleted and the window is disposed of.

Listing 3-6 Disposing of a text object
Boolean MyDisposeObject (WindowPtr theWindow) { TXNObject textObject = NULL; Boolean okToClose = true; // Use your own function to get the text object associated // with the window. MyGetTextObject (theWindow, &textObject); // If the text object has been changed, if (TXNGetChangeCount (textObject)) // call your function to show the save dialog and // give the user an opportunity to save the text object to a file. okToClose = MyDoSaveDialog (window, textObject); if (okToClose) { // Call the MLTE function to dispose of the text object. TXNDeleteObject (textObject); // Call the Window Manager function to dispose of the window. DisposeWindow (theWindow); } // Return result. return okToClose; }

Copyright © 2001 Apple Computer, Inc. (Last Updated January 11, 2001)

Up   Previous   Next