Autor Beitrag
Max
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Di 25.06.02 04:15 
Hallo !

Wie kann ich eine Prozedur schreiben , wo ich ein True zurück bekomme ,
wenn sich eine CD im Laufwerk befindet und eben so ein FALSE wenn
keine drin ist ??

Danke
Max :?
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 25.06.02 05:26 
Hallo,

bei den Schweizern findest du ein Beispiel, das dir TRUE zurückliefert wenn eine AUDIO-CD im Laufwerk ist. Mit ein paar kleinen Modifikationen kannst du das in die von dir gwünschte Funktion ändern.

Gruß
Klabautermann
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Di 25.06.02 08:01 
Moinsen!

Und hier eine allgemeine Methode.
Gilt nicht nur für CD-ROM-Laufwerke, sondern für alle Laufwerke.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function DiskInDrive(Drive: Char): Boolean;
var  ErrorMode: word;
begin
 Drive := UpCase(Drive);
 if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Disc-ID not allowed!');
 ErrorMode := SetErrorMode(SEM_FailCriticalErrors or SEM_NOOPENFILEERRORBOX);
 try
  if DiskSize(Ord(Drive) - $40) = -1 then
     Result := False
  else
     Result := True;
 finally
        SetErrorMode(ErrorMode);
 end;
end;

Anwendung beispielsweise:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if DiskInDrive(DriveComboBox1.Drive)=True then
 mache_irgendeinen_mist;
else
 ShowMessage('Kein Medium eingelegt!');


Grüße

Torsten

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 28.08.04 13:04 
Hallo.

Ich habe die Funktion unangetastet gelassen, aber das andere wie folgt geändert:
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:
procedure TForm1.Button11Click(Sender: TObject);
begin
Label33.Caption:='Status:  Suche gestartet - bitte warten!';
application.processmessages;
if DiskInDrive(ComboBox1.Items[ComboBox1.ItemIndex])=False then
 ShowMessage('Kein Medium eingelegt!');
else
if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'alphaaudio\alphaplayer.exe') then
  ListView1.Items.Item[0].SubItems.Add('VORHANDEN!')
  else
  ListView1.Items.Item[0].SubItems.Add('nicht gefunden');

if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'cactuspj.exe') then
  ListView1.Items.Item[1].SubItems.Add('VORHANDEN!')
  else
  ListView1.Items.Item[1].SubItems.Add('nicht gefunden');

if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'player\yucca.cds') then
  ListView1.Items.Item[2].SubItems.Add('VORHANDEN!')
  else
  ListView1.Items.Item[2].SubItems.Add('nicht gefunden');

  Label33.Caption:='Status:  Suche beendet.';
end;


Nun meldet Delphi "incompatible types: 'Char' and 'String'".
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 28.08.04 13:13 
Was steht denn in der Combobox drinne?
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 28.08.04 13:22 
Zzt. nur das Laufwerk, also z.B. F:\ - ach so, darf dafür nur der Laufwerksbuchstabe ausgewertet werden?
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Sa 28.08.04 17:03 
Cool, nach fast zwei Jahren eine Antwort. :)
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 28.08.04 17:07 
Na, wenn ichs jetzt brauch...

Nur weiß ich halt im Mom noch nicht, wie ich das Ding zum Laufen bekomme...

MfG
Thorsten a.k.a. DJ Iltiz
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 28.08.04 17:35 
Zitat:

function DiskInDrive(Drive: Char): Boolean;
...
if DiskInDrive(ComboBox1.Items[ComboBox1.ItemIndex])

diskindrive erwartet einen char, also ein einzelnes Zeichen, du versuchst einen String (mit mehreren Zeichen) zu übergeben. Selbst wenn die einträge der Combobox aus einem Zeichen bestehen, bleiben es trotzdem strings, die der Function nicht übergeben kannst.

ausblenden Delphi-Quelltext
1:
2:
if length(ComboBox1.Items[ComboBox1.ItemIndex])>1 then 
  if DiskInDrive(ComboBox1.Items[ComboBox1.ItemIndex][1])

würdest du das erste Zeichen des Comboboxeintrages übergeben. Die längenprüfung solltest du machen, wenn der Eintrag '' enthält, kracht es sonst. außerdem solltest du prpüfen, ob in der combobox überhaupt was ausgewählt wurde (if ComboBox1.ItemIndex<>-1).

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 28.08.04 18:19 
Okay danke. Das mit der Combobox prüfen muss nicht. Denn wenn nix ausgrewählt ist, ist der Button zum Starten der Aktion deaktiviert :D

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.Button11Click(Sender: TObject);
begin
Label33.Caption:='Status:  Suche gestartet - bitte warten!';
ListView1.Refresh;
application.processmessages;
if length(ComboBox1.Items[ComboBox1.ItemIndex])>1 then
  if DiskInDrive(ComboBox1.Items[ComboBox1.ItemIndex][1])=False then
 ShowMessage('Das Laufwerk ist leer!')
 else
begin
 if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'alphaaudio\alphaplayer.exe') then
  ListView1.Items.Item[0].SubItems[0]:='VORHANDEN!'
  else
  ListView1.Items.Item[0].SubItems[0]:='nicht gefunden';

if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'cactuspj.exe') then
  ListView1.Items.Item[1].SubItems[0]:='VORHANDEN!'
  else
  ListView1.Items.Item[1].SubItems[0]:='nicht gefunden';

if FileExists(ComboBox1.Items[ComboBox1.ItemIndex] + 'player\yucca.cds') then
  begin
  ListView1.Items.Item[2].SubItems[0]:='VORHANDEN!';
  end
  else
  ListView1.Items.Item[2].SubItems[0]:='nicht gefunden';
end;
  Label33.Caption:='Status:  Suche beendet.';
end;
Benutzername
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 210

Win XP Pro
Delphi 7 PE, D2005 Prof. SSL
BeitragVerfasst: Mi 01.09.04 12:19 
Nur so allgemein: Du solltest evtl deine Labels anders nennen, wer kann sich schon was under Label33 vorstellen? :wink:
master cool
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 32

Win XP Home
D3 Prof
BeitragVerfasst: Sa 04.09.04 16:49 
was is´n das mit dem drivecombobox.drive? bei mir bringt der da immer nen fehler!
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 04.09.04 18:18 
master cool hat folgendes geschrieben:
was is´n das mit dem drivecombobox.drive? bei mir bringt der da immer nen fehler!


Du erwartest doch nicht etwa wirklich eine Antwort? Es gibt mehr als einen Fehler, falls du das nicht wissen solltest :roll:

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)