During my long and fruity friendship with Delphi, particularly the 7th version, I have colelcted a large number of helpful standalone classes, VCL components and functions that I’ve been using in various projects. Not so long ago I decided to put them in a separate build which I called D7X (aka «Delphi 7 eXtension» library).
One of the main points behind D7X is complete Unicode support in each and every component. You will see that
pascalString
’s are extremely rare in the code.
It is available from GitHub.
D7X contains lots of handy stuff which is too troublesome (and probably not necessary) to describe in details so only a brief overview is given below. Some of D7X classes have separate articles already published and they will be listed as well.
Directory structure is as follows:
This unit contains two generic «callback» classes.
TCallbackHash – a collection of object callbacks (TMethod); each callback might have a name (Key). After a callback was added it can be retrieved using ToMethod and ToMethodBy methods that will set given variable to the callback; that variable can be used as a function to call the method.
TCallbackHash has most of standard string list features – callbacks can be added, removed, replaced; their names can be duplicated or case-insensitive.
The second class – TArgList – represents an abstract «argument list». Its constructor gets a string that is then parsed into ordered arguments (using a virtual method, by default splitting it by spaces). Then this object can be passed around and its arguments can be accessed as strings or integers (raising exceptions if argument type is invalid or no argument with given index existed).
ColorConsole is a complex unit implementing sophisticated and extensible formatted console output. It allows line centering, colorizing, repeating and so on.
More details – in its own article.
A set of classes for creating console applications in Delphi. It handles localization, console output including formatting using ColorConsole.pas, exception handling, command line processing (options, aliases, etc.) and other common tasks.
Main classes present in this unit are:
This is a basic console application using CommandLine.pas:
pascalprogram D7X_CL; {$APPTYPE CONSOLE} uses Windows, SysUtils, MMSystem, StringsW, CommandLine, MConfig, MTasks; TD7X_CL = class (TCLColorApplication) protected function TryDoingTask(Task: WideString): Boolean; override; public procedure SetInfo; override; end; { TD7X_CL } procedure TD7X_CL.SetInfo; begin Name := 'Test D7X console app'; Version := $0102; // v1.02 Author := 'Myself'; WWW := 'http://proger.i-forge.net'; BuildDate := $21022012; // DD MM YYYY Help := 'Help text goes here.'; HelpDetails := 'This is shown when ran as "help" task.'; TaskAliases['h'] := 'help'; end; function TD7X_CL.TryDoingTask(Task: WideString): Boolean; begin Result := True; if Task = 'test' then ConsoleWriteLn('{<{wi Test} task called.}') else Result := inherited TryDoingTask(Task); end; { Entry point } var App: TD7X_CL; begin App := TD7X_CL.Create; try App.Run; finally ExitCode := App.ExitCode; App.Free; end; end.
«Data providers» is my version of Delphi Streams. Standard streams lack some really useful methods and so I’d decided to make my own variant while writing one of my VN tools.
Basic TDataProvider declares methods for writing numbers, ANSI and Unicode strings and arrays, saving and restoring stream positions, comparing current input, copying data from other data provider or stream, saving current data to a file, etc.
This small unit is used to resolve file name masks with controlled recursion depth, case sensitivity and other parameters.
Typically you would create an instance of TMaskResolver, sets its Mask to some string and then either use HasMore and Next methods within a loop or use single PutNextTo method like this:
pascalvar FileName: WideString; ... while MaskResolver.PutNextTo(FileName) do Memo1.Lines.Add(FileName);
One of the most useful classes – Unicode TFileStream. Apart from Unicode Create method it adds several others:
Ported Unicode IniFiles.pas. Uses ported StringsW.pas. In general it’s identical to the standard Delphi unit but extended with several new methods (e.g. CopyAllFrom, ReadSectionsPrefixed, etc.) added to the end of class declarations.
Delphi 7 interface to SQLite 3 database engine.
Lightweight number and string stack implementations. Unlike standard Delphi TStack and children these are implemented using contiguous memory blocks (arrays) instead of lists.
A template-class for writing binary data into a stream. It handles file header («magic» signature, version and flags), compression (using Zlib) and checksum (using Adler32 from Zlib).
Works for both reading and writing – reading verifies stream and raises exceptions on wrong signature, checksum or other inconsistency.
The main goal of this class is to provide uniform way to read and write binary data delegating handling of compression and other wrapper features to a separated class.
Unicode version of standard Delphi TStrings classes from Classes.pas. Similarly to IniFilesW.pas this unit adds several helpful methods (like CopyTo, LineBreak, JoinValues, etc.) to the end of some -W classes.
Two lightweight wrappers for WinAPI threads and multimedia timers. Note that the latter uses timeSetEvent and other functions that have become obsolete by now.
TSingleThread provides means for starting, terminating, waiting for a single thread, getting its exit code and attaching OnFinish/OnException callbacks.
TMMTimer is similar, accepting a procedure or object callback and calling it with specified intervals.
This unit contains several Unicode label VCL components:
This simple component extends TSpeedButton with PopupMenu property that is shown under the button when it’s clicked. The menu can be customized to show under a different control and on its left, right or center.
Extends TSpeedButton with many useful properties allowing to:
One of the first D7X units – ported Unicode versions of standard TOpenDialog and TSaveDialog. Has the same properties but all of them including Title and Files are Unicode (WideString).
This unit implements Base64 algorithm using Windows CryptoAPI (if it’s available (since Windows XP)) or 3rd party Base64 implementation in native Delphi code. Both parts have been tested to produce matching results (see Tests\Base64).
pascalfunction Base64Encode(Binary: String): String; function Base64Decode(Str: String): String; // use CryptoAPI for calculating Base64 if it's available (enabled by default). procedure TryToUseCrypt32; // force using built-in Base64 implementation. procedure DoNotUseCrypt32;
3rd party CRC32 implementation using preinitialized CRC table.
Replaces standard Delphi VCL Popuplist with custom object that activates 3 global callbacks:
Reverse Polish Notation unIT – or simply RPNit is an engine for calculating expressions written in postfix or notation. It can be extended with custom operators, functions, variables and even operand types.
Technically this is a set of classes but it was expected to be internal so that only a bunch of top-level functions would be exported.
It is used in my ApiHook – Win32 API hooking tool and Lightpath projects.
Small wrapper around standard Windows MultiByteToWideChar and WideCharToMultiByte functions. Apart from this it also converts codepage and charset names into IDs and vice-versa by looking up the registry at HKCL\MIME\Database\Codepage\ and Charset\.
A great variety of Internet-related functions – downloading, uploading, MIME encoding, query building, URL encoding and so on. Mostly wraps around WinAPI functions like InternetReadFile. For example, you can fetch a remote URL in one call with
pascalInetDownloadTo('temp.html', 'http://google.com');
.
One of the two core function units (see Utils.pas) – a collection of all possible functions dealing with Unicode strings – from PosW, Expode, DetectEolnStyleIn and FormatSize to MaskMatch (wildcard matching), Quote and WrapText.
One of the two core function units (see StringUtils.pas) – general-purpose routines that don’t primarily deal with strings (for this StringUtils.pas is used).
This unit contains functions like WriteArray, ParamStrW, ExtractFilePath, CopyToClipboard, ReadRegValue, GetProcessModules and others.