Vcl.Graphics.TCustomCanvas.TryLock

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function TryLock: Boolean;

C++

bool __fastcall TryLock();

Properties

Type Visibility Source Unit Parent
function public
Vcl.Graphics.pas
Vcl.Graphics.hpp
Vcl.Graphics TCustomCanvas

Description

Locks the canvas if it is currently unlocked.

Call TryLock to prevent other threads from writing on the surface of the canvas until the Unlock method is called. Unlike calls to the Lock method, which nest so that every call to Lock must be matched with a subsequent call to Unlock, TryLock need only be matched by a call to Unlock, if the canvas was not already locked.

If the canvas is unlocked, TryLock locks the canvas, sets the LockCount property to 1, and returns true. If the canvas is already locked, TryLock returns false without making any changes.

Use TryLock before attempting changes to the canvas that could interfere with other code that is protected by a Lock/Unlock pair of method calls.

See Also