Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

Delphi.GetProcessReservingFile

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Delphi.GetProcessReservingFile

Returns the process that currently has a given file open, if any.

Heavily influenced by: https://devblogs.microsoft.com/oldnewthing/20120217-00/?p=8283

Usage

pascal
try
  OpenAndProcessFile(LFileName); // your code that opens the file
except
  on E: Exception do
  begin
    ...
    if GetProcessReservingFile(LFileName, LProcessFileName) then
      LErrorMessage := LErrorMessage + ' The process that is holding your file hostage is: "' + LProcessFileName + '"';
  end;
end;