Skip to Main Content
Mastering Delphi Programming: A Complete Reference Guide
book

Mastering Delphi Programming: A Complete Reference Guide

by Primož Gabrijelčič
November 2019
Beginner to intermediate content levelBeginner to intermediate
674 pages
15h
English
Packt Publishing
Content preview from Mastering Delphi Programming: A Complete Reference Guide

Custom locking mechanism

It is actually not that hard to implement a lock pattern in our code without using any external implementation. We only need a little help in the form of the TInterlocked class that I mentioned previously. The Lock (custom) button on the demonstration program activates two methods that use this approach.

The code uses an integer field called FCustomLock: integer as a lock. The logic is very simple; when this field contains a value of 0, access is granted. If the value is 1, access is locked.

The main program creates two threads, one executing CustomLockIncrementValue and another executing CustomLockDecrementingValue. The former is shown here:

procedure TfrmLock.CustomLockIncrementValue;var  i: integer;begin for i := ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Delphi GUI Programming with FireMonkey

Delphi GUI Programming with FireMonkey

Andrea Magni
Delphi Cookbook - Third Edition

Delphi Cookbook - Third Edition

Daniele Spinetti, Daniele Teti

Publisher Resources

ISBN: 9781838989118Other