Board index » delphi » Drive ComboBox and CD-ROM drives

Drive ComboBox and CD-ROM drives

Hi there.

I'll try this forum again since it seems to have a lot of very skilled
readers - and then there's me. :)

I'm new in Delphi and I've started on a project which includes a Drive
ComboBox and a Directory ListBox which are linked together through the
DirList (ComboBox). When I try changing to a drive (e.g. F:) which is
a CD-ROM-drive and a CD-ROM is NOT loaded, the program crashes with a
"Exception Class EInOutError, Message I/O error 21. Process stopped".

I've tried using {$I-} but this doesn't seem to do the trick. I've
come so close that I've found out that the error seem to occur at a
time which I do not know how to intercept and catch the error in time
to stop the error from occuring. Can somebody please help me?

Thanks in advance.

Best regards,
Stig Norre

 

Re:Drive ComboBox and CD-ROM drives


Clear the DirList property and use the following OnChange event handler:

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  try
    DirectoryListBox1.Drive := DriveComboBox1.Drive;
  except
    DriveComboBox1.Drive := DirectoryListBox1.Drive;
  end;
end;

ps. I/O error 21 = ERROR_NOT_READY

"Stig Norre" <s...@at400.dk> schreef in bericht
news:3ae433a6.257670@news.telia.dk...

Quote
> Hi there.

> I'll try this forum again since it seems to have a lot of very skilled
> readers - and then there's me. :)

> I'm new in Delphi and I've started on a project which includes a Drive
> ComboBox and a Directory ListBox which are linked together through the
> DirList (ComboBox). When I try changing to a drive (e.g. F:) which is
> a CD-ROM-drive and a CD-ROM is NOT loaded, the program crashes with a
> "Exception Class EInOutError, Message I/O error 21. Process stopped".

> I've tried using {$I-} but this doesn't seem to do the trick. I've
> come so close that I've found out that the error seem to occur at a
> time which I do not know how to intercept and catch the error in time
> to stop the error from occuring. Can somebody please help me?

> Thanks in advance.

> Best regards,
> Stig Norre

Re:Drive ComboBox and CD-ROM drives


Thank you for helping so fast. I see where you're going but that also
fails (same error)... (although as far as I can read it should work as
you've described.)
This however works in the way that it tests the drive:

procedure TMainForm.DriveComboChange(Sender: TObject);
VAR
  SR : TSearchRec;

begin
 {$I-}
 IF FindFirst(DriveCombo.Drive+':\*.*',faAnyFile,SR) = 0 THEN DirListBox.Drive := DriveCombo.Drive
 ELSE DriveCombo.Drive := DirListBox.Drive;
 {$I+}
end;

The only thing is, that it resets all directories to root dir. Any
other ideas???.. ;)

Best regards,
Stig

(I'm using Delphi III if this has any effect)

On Mon, 23 Apr 2001 16:14:19 +0200, "M.H. Avegaart"

Quote
<avegaartNOS...@mccomm.nl> wrote:
>Clear the DirList property and use the following OnChange event handler:

>procedure TForm1.DriveComboBox1Change(Sender: TObject);
>begin
>  try
>    DirectoryListBox1.Drive := DriveComboBox1.Drive;
>  except
>    DriveComboBox1.Drive := DirectoryListBox1.Drive;
>  end;
>end;

>ps. I/O error 21 = ERROR_NOT_READY

>"Stig Norre" <s...@at400.dk> schreef in bericht
>news:3ae433a6.257670@news.telia.dk...
>> Hi there.

>> I'll try this forum again since it seems to have a lot of very skilled
>> readers - and then there's me. :)

>> I'm new in Delphi and I've started on a project which includes a Drive
>> ComboBox and a Directory ListBox which are linked together through the
>> DirList (ComboBox). When I try changing to a drive (e.g. F:) which is
>> a CD-ROM-drive and a CD-ROM is NOT loaded, the program crashes with a
>> "Exception Class EInOutError, Message I/O error 21. Process stopped".

>> I've tried using {$I-} but this doesn't seem to do the trick. I've
>> come so close that I've found out that the error seem to occur at a
>> time which I do not know how to intercept and catch the error in time
>> to stop the error from occuring. Can somebody please help me?

>> Thanks in advance.

>> Best regards,
>> Stig Norre

Re:Drive ComboBox and CD-ROM drives


"Stig Norre" <s...@at400.dk> a crit dans le
message news: 3ae45c76.10705__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__@news.telia.dk...

Quote
> Thank you for helping so fast. I see where

you're going but that also
Quote
> fails (same error)... (although as far as I can

read it should work as

Quote
> you've described.)

Are you getting the error at compile time or when
running the controlled programme. If yes for the
former and no for the latter, try disactivating
the option "Stop on Error" in the options menu of
Delphi. I had this the other day while using a
perfectly correct try..except, it took me an hour
to twig why!

John

Re:Drive ComboBox and CD-ROM drives


Well, it only happens at runtime... But thanks anyway.. ;)

On Mon, 23 Apr 2001 20:43:49 +0200, "John of Aix"

Quote
<DOnotSPAMj.mur...@libertysurf.fr> wrote:

>"Stig Norre" <s...@at400.dk> a crit dans le
>message news: 3ae45c76.10705__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__@news.telia.dk...
>> Thank you for helping so fast. I see where
>you're going but that also
>> fails (same error)... (although as far as I can
>read it should work as
>> you've described.)

>Are you getting the error at compile time or when
>running the controlled programme. If yes for the
>former and no for the latter, try disactivating
>the option "Stop on Error" in the options menu of
>Delphi. I had this the other day while using a
>perfectly correct try..except, it took me an hour
>to twig why!

>John

Re:Drive ComboBox and CD-ROM drives


Quote
"Stig Norre" <s...@at400.dk> wrote in message

news:3ae433a6.257670@news.telia.dk...

Quote
> Hi there.

> I'll try this forum again since it seems to have a lot of very skilled
> readers - and then there's me. :)

> I'm new in Delphi and I've started on a project which includes a Drive
> ComboBox and a Directory ListBox which are linked together through the
> DirList (ComboBox). When I try changing to a drive (e.g. F:) which is
> a CD-ROM-drive and a CD-ROM is NOT loaded, the program crashes with a
> "Exception Class EInOutError, Message I/O error 21. Process stopped".

> I've tried using {$I-} but this doesn't seem to do the trick. I've
> come so close that I've found out that the error seem to occur at a
> time which I do not know how to intercept and catch the error in time
> to stop the error from occuring. Can somebody please help me?

> Thanks in advance.

> Best regards,
> Stig Norre

This might work:

var
  Dummy: Cardinal;
  Return: Boolean;
begin
  Return := GetDiskFreeSpace('c:\', Dummy, Dummy, Dummy, Dummy);
  if Return then
  begin
    Label2.Caption := 'Drive exists';
  end
  else
  begin
    Label2.Caption := 'Drive does not exist';
  end;
end;

Regards Andrew
http://www.freesoft.fsnet.co.uk

Re:Drive ComboBox and CD-ROM drives


The message <3ae433a6.257...@news.telia.dk>
  from  s...@at400.dk (Stig Norre) contains these words:

Quote
> Hi there.
> I'll try this forum again since it seems to have a lot of very skilled
> readers - and then there's me. :)
> I'm new in Delphi and I've started on a project which includes a Drive
> ComboBox and a Directory ListBox which are linked together through the
> DirList (ComboBox). When I try changing to a drive (e.g. F:) which is
> a CD-ROM-drive and a CD-ROM is NOT loaded, the program crashes with a
> "Exception Class EInOutError, Message I/O error 21. Process stopped".
> I've tried using {$I-} but this doesn't seem to do the trick. I've
> come so close that I've found out that the error seem to occur at a
> time which I do not know how to intercept and catch the error in time
> to stop the error from occuring. Can somebody please help me?
> Thanks in advance.
> Best regards,
> Stig Norre

Hi,

I/O Error 21 is the normal exception message you get when a CD or
floppy is not in the drive. Unless there is something really screwed
up with your Delphi installation, it should not stop an executable
which is running outside the IDE. If you have break on exception
checked then, it will stop when you are debugging.

In my program I have suppressed it by resetting the Drivelistbox
back to the last known good drive.

Here is part of the exception handler from my program.
{==================
 Exception Handler
 ==================}
procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
if Sender = Panel4 then     //filelistbox,drivelistbox,directorylistbox
     begin
     DriveCombobox1.Drive:=DriveListBox1.Drive;
     exit;
     end;
   ......
   ......

if not (E is ENewReg) then  //My own registry component don't worry about it
       application.Showexception(E);
end;

You assign an exception handler in the Form Create method like this:

TForm1.FormCreate(sender:TObject)
begin
application.OnException:=AppException;
...
...
end;

You need to declare a prototype for it in the private section of your
Form's class.

like this

{private}
......
......
procedure AppException(Sender: TObject; E: Exception);

All of the file selection components sit on panel4 in my program so I
detect exceptions comming from panel4, you will need to modify this
to suit your program I have left one other bit in, because it
illustrates one very important thing you need to do. You must not
suppress error messages from other exceptions so you must call
Application.Showexception for all unhandled exceptions.

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)

Re:Drive ComboBox and CD-ROM drives


The message <2001042523555280...@zetnet.co.uk>
  from  Andreas Kyriacou <andrik...@zetnet.co.uk> contains these words:

Quote
> {==================
>  Exception Handler
>  ==================}
> procedure TForm1.AppException(Sender: TObject; E: Exception);
> begin
> if Sender = Panel4 then     //filelistbox,drivelistbox,directorylistbox
>      begin
>      DriveCombobox1.Drive:=DriveListBox1.Drive;<---Woops!
>      exit;
>      end;

DriveCombobox1.Drive:=DriveListBox1.Drive;<---Woops!

should Read

DriveCombobox1.Drive:=DirectoryListBox1.Drive;<---Woops!

Error Comes from expanding out abbreviated names, sorry.

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)

Other Threads