Recent

Author Topic: check if file is in use?  (Read 7771 times)

hh

  • Newbie
  • Posts: 2
check if file is in use?
« on: March 02, 2010, 03:54:54 pm »
i only found code for delphi
Code: [Select]
function IsFileInUse(FileName: TFileName): Boolean;
var
  HFileRes: HFILE;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  HFileRes := CreateFile(PChar(FileName),
                         GENERIC_READ or GENERIC_WRITE,
                         0,
                         nil,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL,
                         0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(HFileRes);
end;

eny

  • Hero Member
  • *****
  • Posts: 1648
Re: check if file is in use?
« Reply #1 on: March 02, 2010, 05:52:21 pm »
Have a look at FileOpen in SysUtils for the correct Lazarus equivalent for parameter and return types (basically: HFILE is replaced with THandle).
« Last Edit: March 02, 2010, 05:53:56 pm by eny »
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

 

TinyPortal © 2005-2018