Autor Beitrag
fabi65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mi 18.05.05 17:20 
ich habe bereits in der FAQ gesehen das es da eine Funktion gibt und sie so eingefügt:
ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function DiskInDrive(Drive: Char): Boolean;
var  
  ErrorMode: Word;  
begin
  Result := False;  


  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  
    Result := DiskSize(Ord(Drive) - $40) = -1;
  finally
    SetErrorMode(ErrorMode);
  end;
end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

end.



Es kommt aber trotzdem immer eine Fehlermeldung:
Zitat:

[Error] Unit1.pas(20): Statements not allowed in interface part
[Error] Unit1.pas(21): Undeclared identifier: 'Result'
[Error] Unit1.pas(24): Undeclared identifier: 'Drive'
[Error] Unit1.pas(17): Unsatisfied forward or external declaration: 'DiskInDrive'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 18.05.05 17:35 
ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
 unit Unit1;  

 
interface  

 
uses  
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  Dialogs;  

 
type  
  TForm1 = class(TForm)  
  private  
    { Private declarations }  
  public  
    { Public declarations }  
  end;  

  
var  
  Form1: TForm1;  

 
implementation  

 
{$R *.dfm}  


function DiskInDrive(Drive: Char): Boolean;  
var    
  ErrorMode: Word;    
begin  
  Result := False;  
 
  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    
    Result := DiskSize(Ord(Drive) - $40) = -1;  
  finally  
    SetErrorMode(ErrorMode);  
  end;  
end;  


 
end.


wie wärs mit nem anfänger tutorial ? :idea:
fabi65 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Do 19.05.05 18:04 
wie kann ich jetzt abfragen ob das medium jetzt eingelegt ist :oops:
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 19.05.05 18:08 
wie wärs mit was leichterem, wie gesagt, n angfänger tut kann nich schaden, dann wüsstest du es, weil du ja schon den code falsch reinkopiert hast :idea:

nur son tipp: du musst die funktion aufrufen :)
fabi65 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Do 19.05.05 20:28 
schätze mal das es so geht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
test:Char;
begin
DiskInDrive(test);
end;


nur wie kann ich jetzt mit einer char vari eine if anweisung machen?
fabi65 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Do 19.05.05 22:34 
habe es jetzt so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function IsDiskInDrive(const ADrive: Char) : Boolean;
var ErrorMode: word;
begin
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
 try   Result := (DiskSize(Ord(UpperCase(ADrive)[1]) - 64) > -1);
  finally
  SetErrorMode(ErrorMode);
  end;
  end;


ausblenden Quelltext
1:
2:
if IsDiskInDrive('X' {irgendein Laufwerksbuchstabe} ) then ShowMessage('Is drinne... *freu*')
else ShowMessage('Dat Ding is ja leer!');
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 20.05.05 14:58 
ja so :D
3rdnuss
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 139



BeitragVerfasst: Fr 20.05.05 15:35 
Ne ganz einfache Methode ist die:
ausblenden Quelltext
1:
if  not fileexists('c:\') or fileexists('d:\') then..					


Dabei wird aber ausgegangen, dass mindestens 1 Datei vorhanden ist.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 20.05.05 15:37 
die prozedur arbeit ja ähnlich, aber ist auch mal ne möglichkeit :D