There is no easy way to write a drive formatting function or procedure. The easiest way is to let Windows do it for you by showing the standard Windows format dialog for floppies. The dialog will be modal and displays any error or success messages, so no messages are needed to be displayed in this procedure. Call FormatFloppy(0) to format the A:\ drive or FormatFloppy(1) for the B:\ drive.
procedureFormatFloppy(Drive: byte); { proc to show the standard Windows format dialog to format a } { floppy drive. Pass 0 for A:\ or 1 for B:\ } type TSHFormatDrive = function (hWnd: HWND; Drive: Word; fmtID: Word; Options: Word): Longint stdcall; var SHFormatDrive: TSHFormatDrive; LibHandle: THandle; begin LibHandle := LoadLibrary(PChar('Shell32.dll')); if LibHandle <> 0 then @SHFormatDrive := GetProcAddress(LibHandle, 'SHFormatDrive') else begin MessageDlg('Failed to load Shell32.dll.', mtError, [mbOK], 0); Exit; end;
if @SHFormatDrive <> nilthen SHFormatDrive(Application.Handle, Drive, { 0 = A:\, 1 = B:\ } $FFFF, 0);
FreeLibrary(LibHandle); @SHFormatDrive := nil; end;