Autor Beitrag
Flash106
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 12:37 
Hallo,

ich habe eine DriveComboBox die logischer Weise einen Fehler ausspuckt wenn ich auf ein CD oder DVD laufwerk klicke und dort kein Datenträger einliegt. Ich möchte den Fehler eigentlich nur unterbinden ODER wenigstens "umbenennen", also so, dass dann steht "Kein Datenträger im Laufwerk" anstatt "E/A-Fehler 21". Aus den Einträgen im Forum habe ich irgendwie nichts passendes gefunden. Sollte ich was übersehen haben entschuldige ich mich schonmalim vorraus. Danke schonmal!!

flash106
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 12:57 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
try
//Öffne Laufwerk
except
on ExceptionName do
showmessage('Kein Datenträger im Laufwerk');
end;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 13:04 
Also das sieht schon sehr gut aus. Wo packe ich das am besten rein und wie kann ich einen source für "öffne laufwerk" schreiben? Bin über die Antwort dankbar!! Reicht mir dann auch so denke ich :D
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:12 
user profile iconFlash106 hat folgendes geschrieben:
Wo packe ich das am besten rein

Na da wo die Exception auftritt :roll:
user profile iconFlash106 hat folgendes geschrieben:
und wie kann ich einen source für "öffne laufwerk" schreiben?

Dort schreibst du den Code rein, der unter Umständen die Exception auslöst.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:13 

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 13:14 
hmm.. die exception tritt auf wenn ich ein laufwerksbuchstabe wähle F: z.b. und da liegt keine cd drinn. und ein code für das wechseln des laufwerks habe ich ja nicht das macht ja die combo.. deshalb meine frage sorry... :(
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:17 
user profile iconFlash106 hat folgendes geschrieben:
hmm.. die exception tritt auf wenn ich ein laufwerksbuchstabe wähle F: z.b. und da liegt keine cd drinn. und ein code für das wechseln des laufwerks habe ich ja nicht das macht ja die combo.. deshalb meine frage sorry... :(

War nicht so gemeint :zwinker:
Welche Komponente benutzt du? TComboBox oder was?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 13:28 
Das ist die TDriveComboBox und in der DirectoryListBox werden die Dateien angezeigt. Sind gekoppelt die beiden.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:33 
Ich glaub da muss man tief in die VCL eingreifen, da der Fehler nicht durch einen Code von dir ausgelöst wird, sondern von den Komponenten selber, wobei ich nicht eimmal sagen kann, wer es überhaupt ist :-(

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 13:42 
herjie... das is ja jetzt doof. Jetzt wird der User mit soner blöden Fehlermeldung angemobbt und weis nich was los ist :( ... *schnief* ... hmmm.... vielleicht hat ja noch wer eine idee...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:45 
Suche dir doch eine Funktion, die dir die Dateien selber sucht. Dann kannst du auch TComboBox nehmen. Du packst dann den Code zum Suchen in den try except Block und fängst damit Fehler ab.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 13:47 
Leichter gesagt als getan ^^. Naja muss ich mal schaun. Danke für deine Hilfe!
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 28.05.06 13:50 

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 28.05.06 13:55 
Hier mal was aus einem älteren Prog von mir mit Combobox zum anzeigen der Laufwerke vieleicht hilft Dir das was.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
procedure TForm1.FormCreate(Sender: TObject);
var
 x: Byte;
 d: DWord;
begin
  ComboBox1.Text:='Laufwerk ?';
  d := GetLogicalDrives;
   for x := 0 to 31 do begin
    if odd(d) then
  ComboBox1.Items.add(chr(x+65));
  d := d shr 1;
 end;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var
Errormode: word;
begin
  if Combobox1.ItemIndex>0 then Listebutton.Enabled:=True;
  if Combobox1.ItemIndex=0 then
begin
 Errormode := SetErrorMode(SEM_FAILCRITICALERRORS);
 if Diskfree(1)=-1 then
 ShowMessage('Keine Diskette in Laufwerk A: !');
 if Diskfree(1)=-1 then Listebutton.Enabled:=False else Listebutton.Enabled:=True;
 SetErrorMode(Errormode);
end;
end;
end.
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 14:13 
ah verstehe. Eine eigene ComboBox. Gut versuche ich mal umzusetzen sieht sehr gut aus. Melde mich wenns geklappt hat!!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 28.05.06 14:18 
Hallo,

der Fehler wird ausgelöst nach der Übergabe von DriveComboBox.Drive an DirectoryListBox.Drive, also durch die DirectoryListBox. Wenn du dazwischen Einfluss nehmen willst, musst du die Koppelung lösen, und Drive selbst zuweisen. Dafür steht Dir OnChange der DriveComboBox zur Verfügung.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 14:44 
COOOOL. Das klingt sehr gut. Vielen DANK!!!! Mache mich mal an die umsetzung. Klingt sehr einleuchtend!!!
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 14:50 
Ok fast! Habs so eingebunden. Is das korrekt?!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm.DriveComboBoxChange(Sender: TObject);
begin
  try
    DirectoryListBox.Directory := DriveComboBox.Drive + ':\';
  except
  on EInOutError do
  showmessage('Kein Datenträger im Laufwerk');
  end;
end;


Die messagebox erscheint allerdings 2mal! Das muss noch weg dann bin ich hunderpro zufrieden!!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 28.05.06 15:56 
Hallo,

Onchange wird durch das Auswählen eines Laufwerks zweimal ausgelöst.

So sollte es richtig sein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.DriveComboBox1Change(Sender: TObject);
var Errormode: word;
    aDrive : Char;
begin
  //DriveComboBox1.TextCase auf tcLowerCase ?
  aDrive := UpCase(DriveComboBox1.Drive);
  //mehrmaliges onChange berücksichtigen
  if UpCase(DirectoryListBox1.Drive) <> aDrive then
    begin
    Errormode := SetErrorMode(SEM_FAILCRITICALERRORS);//Systemmeldung ausschalten
    if Diskfree(ord(aDrive)-64)=-1 then
      begin
      showmessage('Datenträger nicht formatiert oder kein Datenträger im Laufwerk "'+aDrive + ':\"');
      //zurücksetzen auf zuletzt gewähltes Laufwerk
      DriveComboBox1.Drive := DirectoryListBox1.Drive;
      end
      else
        DirectoryListBox1.Drive := aDrive;
    SetErrorMode(Errormode);
    end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: So 28.05.06 17:43 
Suuuper! Danke!!!