Solved

Drive exception handling

Posted on 2003-11-29
2
192 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
ID: 9844282
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
ID: 9844906
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

21 Experts available now in Live!

Get 1:1 Help Now