Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Floppydisk in floppydrive?

How do I find when there is a floppydisk in the floppydrive???? I tried something like:

function FloppyInFloppyDrive:boolean;
begin
  result:=not Diskfree(0)=-1;
end;

But Windows comes up with at dialogbox which says "Insert disk" - OK, CANCEL ect.

Any ideess?
0
hutelihut
Asked:
hutelihut
1 Solution
 
CodeslaveCommented:
// try the following on a form with a Tlabel and a TButton.
// It is adapted from a code snippet from GExperts.

procedure TForm1.Button1Click(Sender: TObject);
var
  ErrorMode : Word;
begin
  ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    { Check for drive here }
    if DiskFree(1) = -1 then
      Label1.Caption := 'Not Installed'
    else
      Label1.Caption := 'Disk Installed';
  finally
    SetErrorMode(ErrorMode);
  end;
end;

0
 
ginsonicCommented:
function DiskInDrive(Drive: Char): Boolean;
var ErrorMode: word;
begin
  if Drive in ['a'..'z'] then Dec(Drive, $20);
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    if DiskSize(Ord(Drive) - $40) = -1 then
      Result := False
    else
      Result := True;
  finally
    SetErrorMode(ErrorMode);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var DriveStr : String;
begin
 DriveStr := 'a:\';
 If DiskInDrive(DriveStr[1]) Then
  ShowMessage('There is a disk in Drive ' + AnsiUpperCase(DriveStr[1]))
   Else
  ShowMessage('Drive ' + AnsiUpperCase(DriveStr[1]) + ' has no disk')
end;
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now