Solved

Detecting open files in Delphi

Posted on 1998-05-14
2
893 Views
Last Modified: 2010-05-18
Is there a way to detect if a file of any kind (for example .mp3-files) is opened? I want to know if a mp3-file is being played on the computer where my app is installed.
0
Comment
Question by:johnrt
2 Comments
 
LVL 1

Accepted Solution

by:
Socrates050697 earned 100 total points
ID: 1345748
The only way I know to do this is to try opening the file with exclusive access. If the file is already open then it fails. Heres a function to do it -

note: this function will also return false if the file doesn't exist.

function isFileOpen(Filename: string): boolean;
var
  MyOfStruct: TOfStruct;
  FileHandle: integer;
begin
  FileHandle:=OpenFile(Filename,MyOfStruct,OF_SHARE_EXCLUSIVE);
  if FileHandle=HFILE_ERROR then
  begin
    result:=False;
  end
  else
  begin
    result:=True;
    CloseHandle(FileHandle);
  end;
end;

Hope this helps
Socrates
0
 

Author Comment

by:johnrt
ID: 1345749
Thank you. I'll try it...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question