• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Locked Files

How do you detect if another process has locked a file (e.g. is writing to it) in Delphi 4?
0
johnstoned
Asked:
johnstoned
1 Solution
 
TheNeilCommented:
No idea of a 'proper' solution but what you could try is this:

AssignFile(data_in, <filename>);
{$I-}
Reset(data_in);
{$I+}
IF IOError <> 0
THEN
  MessageDlg('File is locked', mtWarning, [mbOk], 0);

CloseFile(data_in);

The Neil
0
 
XANCommented:
well, you can call WinAPI function GetLastError and check it's number

error code: 33
message: The process cannot access the file because another process has locked a portion of the file.
const: ERROR_LOCK_VIOLATION
error code: 108
message: The disk is in use or locked by another process.
const: ERROR_DRIVE_LOCKED

Good Luck
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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