Archive for the ‘Technical Articles’ Category

How to serialize a TList of objects with Delphi

Some weeks ago a customer asked to me if it is possibile serialize a TList of objects. “Hey, you should use a TObjectList for this”, I said, but he absolutely needs (I dont know why) of a TList.
This is the (simple) sample code tested with Delphi XE2 Update4. Enjoy.
unit Unit4;
 
interface
 
uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  [...]

How to Using Hash Tables TDictionary in Delphi

Introduced in Delphi 2009, the TDictionary class, defined in Generics.Collections unit, represents a generic hash table type collection of key-value pairs.
Generic types, again introduced in Delphi 2009, allow you to define classes that don’t specifically define the type of data members.
A dictionary is, in a way, similar to an array. In an array you would [...]

Mutant records: on methods (and helpers)

When “record with methods” were introduced, an important feature was overlooked: mutability. This article discusses the problem, and introduces a possible syntax extension to solve it. Ideas & comments welcome!
The Problem
Effectively, “records with methods” treat all record “const” elements as “var“, even when they shouldn’t, and effectively ignores the compiler option “assignable constants”. Witness the [...]

Add A Grab Bar To The TSplitter

The TSplitter Delphi component is a nice one. I have dozens of them on my complex forms.
The TSplitter divides the client area of a control (the one like TPanel or TForm accepting other controls) into resizable panes. Having the splitter between two aligned controls allows users to resize the controls at runtime.
Imagine two panels on [...]

Threaded Delphi Tasks In A Thread Pool By OmniThreadLibrary

The OTL developed by Primoz Gabrijelcic is a simple to use threading library for Delphi. The “is simple” means that Gabriel has successfully hidden from you the complexity of running tasks in threads where thread synchronization and critical sections for data protection are nicely handled by the OTL.
While OTL is easy to use, one needs [...]