Important: The information in this document is obsolete and should not be used for new development.
Erasing Initialized Disks
You can use the standard interface provided by theDIBadMountfunction to reinitialize disks that are already initialized correctly. Doing so permanently erases their contents, but does not change their names.To reinitialize a disk, call
DIBadMountwith the high word of the event message equal to the result codenoErr. TheDIBadMountfunction presents the standard interface to initialize the disk in the drive whose number is specified by the low word of the event message. However, because the Disk Initialization Manager cannot know why your application wishes to reinitialize a disk, it cannot provide the initial text for the disk initialization dialog box. Therefore, your application must use the Dialog Manager'sParamTextprocedure to create a customized message, as illustrated in Listing 5-2.If you need to reinitialize a valid disk but do not have access to the event message from when the disk was formatted, you can artificially create an event message by setting the event message to an integer representing the drive number, as follows:
myEvent.message := driveNum;Doing so sets each of the high-order bits of the artificial event message to 0, which is desired because the constantnoErris equal to 0.Listing 5-2 defines a procedure for displaying a disk initialization dialog box that allows the user to reinitialize the disk in the drive specified by
driveNum. The disk initialization dialog box displays the text specified in themyStringparameter. The procedure in Listing 5-2 in turn calls a procedure namedDoError. You must defineDoErrorto
process the result code if the initialization did not successfully complete. The disk initialization dialog box does alert the user if the operation is not successfully completed, and the disk is ejected. However, your application might need to know that a formerly mounted disk is no longer mounted because reinitialization failed.Listing 5-2 Reinitializing a valid disk
PROCEDURE DoEraseDisk (driveNum: Integer; myString: Str255); VAR myPoint: Point; myErr: Integer; {result code} BEGIN DILoad; {load Disk Initialization Manager} ParamText(myString, '', '', ''); {set dialog text} SetPt(myPoint, 120, 120); {set top left of dialog box} myErr := DIBadMount(myPoint, driveNum); {allow user to confirm erase} IF myErr <> noErr THEN DoError(myErr); {respond to error, if necessary} DIUnload; {unload Disk Initialization Manager} END;