Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drive exception handling

Posted on 2003-11-29
2
Medium Priority
?
203 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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