FileLocked
Function FileLocked( const aFilePath : string) : boolean
Example
procedure ScriptEvent(var Value: variant);
begin
Value := FileLocked('C:\Fictional\Inbound\order.xml');
end;
Usage
FileLocked reports whether Velox cannot open a path for read/write access while denying other writers.
Parameters
| Name | Type | Description |
|---|---|---|
aFilePath | string, const | Literal file path to probe. Wildcards are not expanded by Velox open. |
Returns
False when FileOpen(aFilePath, fmOpenReadWrite or fmShareDenyWrite) returns a valid handle; otherwise True.
Behaviour
- A compatible existing writable file normally returns
False. - A file held with an incompatible sharing mode returns
True. - The probe itself briefly prevents other writers while its handle is open.
- No handle or lock remains after return.
Important usage notes
Truedoes not specifically prove another process holds a lock. Missing files, read-only media/attributes, denied permissions, directories, invalid paths and unavailable shares also fail the requested read/write open.- A file can be readable but still report
Truebecause write access is requested. - A current compatible open does not guarantee the next open; another actor can change sharing or delete/replace the path immediately.
- Relative paths depend on shared across the Velox process current-directory state.
Errors
All ordinary open errors are collapsed to True; no last-error code or exception is exposed.
Additional Technical Info
FileLocked returns False only when Velox can briefly open the path for both reading and writing while allowing other readers but denying other writers. Every open failure is reported as True.
The example is source-reviewed and was not executed by the documentation workflow.
Implementation
Installed Delphi FileOpen maps this mode to Win32 CreateFileW with GENERIC_READ or GENERIC_WRITE, share mode FILE_SHARE_READ, OPEN_EXISTING and FILE_ATTRIBUTE_NORMAL. Velox closes a successful handle immediately.
Side effects
Opens and closes the file on success. It does not modify file content, but the temporary share mode can briefly affect competing opens.
Performance and concurrency
One synchronous open/close probe. Network paths can block. The result is a momentary observation, not a durable concurrency primitive.
Remarks
Interpret the result as “not openable with this exact mode.” Handle the real open/write operation's result even after False.
Related entries
WaitForFileLockReleaserepeats this same ambiguous probe.FileIsReadOnlychecks only the enumerated attribute.FileExistsdoes not prove this access mode is available.
External references
- Embarcadero
System.SysUtils.FileOpen - Microsoft
CreateFileW- exact Windows access/share terminal used by installed Delphi. - Free Pascal
FileOpen- compatible API context; sharing behavior here is the Windows Delphi terminal above.