Solved

Drive exception handling

Posted on 2003-11-29
2
199 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

626 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