home *** CD-ROM | disk | FTP | other *** search
- unit Diskerr;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Label1: TLabel;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- const
- CR = Chr(13); { carriage return }
- var
- StartDir : string;
- X : Word;
- begin
- GetDir(0,StartDir); { get current directory }
- { turn off Windows error messages }
- { SetErrorMode is an API function }
- X := SetErrorMode(SEM_FAILCRITICALERRORS);
- try { start of protected block }
- ChDir( 'A:\' );
- except { end of protected block }
- { followed by exception handling }
- on E: Exception do
- begin
- ChDir( StartDir ); { go back to original directory }
- { Note the use of E.Message which lets me include }
- { the error description in a dialogue box. }
- MessageDlg('ERROR! Can''t change drive (' + E.Message + ')!'
- + CR + 'Going back to '+StartDir,mtInformation,[mbOK],0);
- end;
- end; { end of try...except block }
- end;
-
- end.
-