Solved

Drive exception handling

Posted on 2003-11-29
2
191 Views
Last Modified: 2010-04-05
Hi, i have a code here that would handle if there is a diskette in drive a:\. What i what is if the error appears and the user press retry it will continue to read until the there is diskette if it pressed the cancel then it will exit. can you please help me?

 if Messagebox(Application.Handle,'Please insert Diskette in Drive A:\','Insert Diskette',
      MB_OKCANCEL+MB_ICONINFORMATION+MB_DEFBUTTON1) = ID_OK then
   begin
     try
               EMode := SetErrorMode(SEM_FAILCRITICALERRORS);
       try
          if DiskSize(Ord('A')-$40) = -1 then
             RaiseLastWin32Error;
       except
            on EWin32Error do
            begin
              LastError:=GetLastError;
             case LastError of
               15:   Messagebox(Application.Handle,'Please insert Diskette in Drive A:\','Insert Diskette',
                       MB_RETRYCANCEL+MB_ICONERROR+MB_DEFBUTTON1)
             end;
            end;
       end;
    finally
      SetErrorMode(EMode);
 end;
0
Comment
Question by:oracle_beginner
  • 2
2 Comments
 
LVL 5

Expert Comment

by:Darth_helge
Comment Utility
how about creating a function that returns a value?
like this:

function DiskInDriveA: Boolean;
var
   OldErrMode: UInt;
begin
   OldErrMode := SetErrorMode(sem_FailCriticalErrors);
   try
     Result := DiskSize(1) <> -1;
   finally
     SetErrorMode(OldErrMode);
   end;
end;

and then you can use for example:

procedure TForm1.Button1Click(Sender: TObject);
begin
 repeat
  if not DiskInDriveA then
 until MessageDlg('No disk in drive. Retry or Cancel?', mtConfirmation, [mbRetry, mbCancel], 0) = mrCancel;
end;

this code is checked and is working!

hope it helps
0
 
LVL 5

Accepted Solution

by:
Darth_helge earned 250 total points
Comment Utility
or alternately, if this is easier to read:

procedure TForm1.Button1Click(Sender: TObject);
var
userInput: integer;
begin
 repeat
  userInput := mrCancel;
  if not DiskInDriveA then
    userInput := MessageDlg('No disk in drive. Retry or Cancel?', mtConfirmation, [mbRetry, mbCancel], 0);
  until userInput = mrCancel;

end;
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now