Jak wybiorę w DriveComboBoxie napęd CD, w którym nie ma aktualnie płyty wywala mi błąd...Co zrobić, żeby po wybraniu pustego napędu wyświetlić np. prośbę o włożenie płyty ?? [glowa]
Proponuje zrobić to tak z
try
To nic nie daje...Chyba, że robię coś źle...Oto kawałek kodu:
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
try
DirectoryListBox1.Update;
except
ShowMessage('Błąd!!!');
end;
end;
I po wybraniu pustego napędu CD pojawia się komunikat "I/O Error 21" Może jest jakiś inny sposób...
try
DirectoryListBox1.Update;
Stosujesz procedurę Update dla komponentu TDirectoryListBox zupełnie nie wiadomo w jakim celu (Update znaczy to samo, co Refresh, czyli odśwież zawartość - The update command repaints the current frame into the specified device context (DC)). Pojawiający się błąd, to NOT_READY - Urządzenie nie jest gotowe (nr błędu: 21). Należy obsłużyć ten wyjątek za pomocą deklaracji try...except
Dla przykładu:
try
...
except
on EInOutError do
ShowMessage('Urządzenie nie jest gotowe');
end;
Co na ten temat sądzi pomoc Delphi:
EInOutError is raised when an file input/output error occurs, provided I/O checking is enabled.
In Delphi code, use the
{$I+}
directive to enable I/O checking. If an I/O error occurs while this directive is disabled, the application must call IOResult to clear the error.
Ja rozwiązałem ten problem inaczej i działa.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Forms,
Dialogs, StdCtrls, FileCtrl, Controls;
type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
procedure DriveComboBox1Click(Sender: TObject);
procedure DriveComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
NextDrive : Char;
PreviousDrive : Char;
PreviousDirListDriveCombobox: TDirectoryListBox;
implementation
{$R *.dfm}
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
NextDrive := DriveComboBox1.Drive;
If DiskFree(Ord(UpCase(NextDrive)) - Ord('A') + 1) <> -1 then
begin
DirectoryListBox1.Drive := DriveComboBox1.Drive;
end
else
begin
ShowMessage('drive not ready');
DriveComboBox1.Drive := PreviousDrive;
DriveComboBox1.DirList := DirectoryListBox1;
end;
end;
procedure TForm1.DriveComboBox1Click(Sender: TObject);
begin
PreviousDrive := DriveComboBox1.Drive;
PreviousDirListDriveCombobox := DriveComboBox1.DirList;
DriveComboBox1.DirList := nil ;
end;
end.
nekrofilu, ten wątek ma PIĘĆ lat!
ale moze sie komuś przyda google dalej je znajduje.
A czy kogoś zastanowił ten fakt, że skoro ten wątek ma pięć lat, to dlaczego nikt go wcześniej tu nie umieścił ?
Proponuj wg mnie coś bardziej prostego...
- ApplicationEvents
- ApplicationEvents.OnException
if E.Message = 'I/O error 21'
then
MessageBox(Handle, 'Urządzenie nie jest gotowe!', 'Blad..', MB_ICONSTOP+MB_OK);