Solved

Drive exception handling

Posted on 2003-11-29
2
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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