Showing posts with label Delphi 2007. Show all posts
Showing posts with label Delphi 2007. Show all posts

The ANSI function to Ansi-fy

CodeGear Delphi 2007, 2009

The ANSI function to Ansi-fy.
This table is not a divine revelation, but my personal reference book.


Ansi-fy Wide Char, Unicode Units
const C = '...'; const C: AnsiString = '...';
CompareText AnsiCompareText SysUtils; AnsiStrings
CompareStr AnsiCompareStr SysUtils; AnsiStrings
FindWindow FindWindowA FindWindowW
(in Delphi Versions >= 2009 the same as FindWindowW)
GetDiskFreeSpace GetDiskFreeSpaceA GetDiskFreeSpace
(in Delphi Versions >= 2009 calls GetDiskFreeSpaceW)
Windows
GetTempPath GetTempPathA GetTempPath
(in Delphi Versions >= 2009 calls GetTempPathW)
Windows
ShellExecute ShellExecuteA ShellExecuteW
(in Delphi Versions >= 2009 the same as ShellExecute)
ShellApi
ShellExecute ShellExecuteA ShellExecuteW
(in Delphi Versions >= 2009 the same as ShellExecute)
ShellApi
ShellExecuteInfo ShellExecuteInfoA ShellExecuteInfoW
(in Delphi Versions >= 2009 the same as ShellExecuteInfo)
SHGetPathFromIDList SHGetPathFromIDListA SHGetPathFromIDList
(in Delphi Versions >= 2009 calls SHGetPathFromIDListW)
ShlObj
StrAlloc AnsiStrAlloc in Delphi Versions >= 2009 StrAlloc calls WideStrAlloc SysUtils
LowerCase AnsiLowerCase LowerCase SysUtils or AnsiStrings (Delphi 2009+)
UpperCase AnsiUpperCase UpperCase SysUtils or AnsiStrings (Delphi 2009+)

This article will not be complete, some text was removed intentionally. If you are unable to apply this, please contact for paid consultation.
Данная статья не будет полной, часть текста была удалена намеренно. Если вам не удалось применить, обращайтесь за платной консультацией.

Differences and Migration Implications from Delphi 2007 to Delphi 2009

CodeGear Delphi 2007, 2009
Official Unicode support was added in Delphi 2009 with code name Tiburón.

In Delphi Versions <= 2007, string was an alias for AnsiString (a single-byte character string type).
In Delphi Versions >= 2009, this changed, and string became an alias for UnicodeString (a multi-byte, UTF-16 character string type), while AnsiString remained available as a type for 8-bit character data.

The change was a major shift to include full Unicode support and has significant implications for the legacy code written in Delphi <= 2007 that is being migrated to Delphi 2009 or later.

Key Differences and Migration Implications

In Delphi 2007 and older (ANSI) Length() returns number of bytes, in Delphi 2009 and newer (Unicode) returns number of characters (elements).

String Alias:
  • Delphi 2007 and earlier: String = AnsiString. The data was 8-bit and its interpretation (code page) was generally linked to the operating system's regional settings.
  • Delphi 2009 and later: String = UnicodeString. The data is 16-bit (WideChar), typically using UTF-16 encoding, allowing for a broad range of characters.
Character Types:
  • Delphi 2007: Char = AnsiChar (8-bit).
  • Delphi 2009: Char = WideChar (16-bit).
Type / Function Delphi 7, 2007 Delphi 2009, XE
byte byte byte (no change)
String AnsiString UnicodeString
Char AnsiChar WideChar
PChar PAnsiChar PWideChar
SizeOf(Char) 1 byte 2 bytes

Data Handling:
  • Direct assignments between AnsiString and the new UnicodeString in Delphi 2009 involve implicit conversions, which can cause to performance issues or, more importantly, data loss if not handled carefully. The compiler will often issue warnings for these conversions.
  • The internal structure of AnsiString itself changed slightly between versions (e.g., in Delphi 2009, it stores a code page number, which was not present in Delphi 2007's AnsiString), making sharing strings between DLLs compiled with different versions problematic.

Migration pieces of Advice

To migrate code that uses strings between these versions, you generally have preferred approaches:
  1. Explicitly Ansi-fy the Code (Short-term fix): Replace all instances of the generic string, Char, and PChar with their explicit 8-bit equivalents: AnsiString, AnsiChar and PAnsiChar. This retains the old behavior but means your application will not leverage Unicode natively and will still encounter conversion overhead when interacting with the rest of the Unicode VCL/RTL in Delphi 2009.
  2. Resort to Unicode: Update your code to use the native UnicodeString type throughout your application. Use AnsiString only at the boundaries where you interact with legacy data, files, or external APIs that require ANSI encoding (e.g., when saving or loading data from an older database). Use functions like TEncoding.GetString to properly decode data.
  3. The correction isn’t simple recompilation, but to audit every PChar, every SizeOf(Char) assumption, and every place where raw bytes to a file or socket expecting ANSI.// Delphi <= 2007 code — assumes 1 byte per char, breaks silently under Unicode procedure TrimBuffer(var Buf: array of Char; MaxLen: Integer); var P: PChar; begin P := @Buf[0]; Inc(P, MaxLen); // wrong stride Char is 2 bytes P^ := #0; end;
  4. Compiler directives and conditional code if code must support both old and new Delphi versions simultaneously.
    The Version constants are not intuitive but they may lead to mistakes:

    {$IFDEF VER150} // Delphi 7 {$IFDEF VER185} // Delphi 2007 Win32 has VER180 & VER185 {$IFDEF VER200} // Delphi 2009 Tiburon {$IFDEF VER210} // Delphi 2010 Weaver

    Another way to use the UNICODE directive:
    {$IFDEF UNICODE} // Delphi 2009+ logic {$ELSE} // Legacy Delphi logic {$ENDIF}

    Prefer to use CompilerVersion than Version constants
    ...
    If the codebase has already passed one migration, it likely has {$IFDEF} blocks keyed to old version constants. Don’t delete these blindly — audit each one with attention.
    Use code with caution!
  5. Compile and watch Fix Warnings: Pay close attention to "Implicit string cast" warnings. They highlight where the compiler is silently converting between ANSI and Unicode strings, which can cause data loss or unplanned behavior.
  6. Character Buffer Allocations with SetLength and GetMem
    If code allocates memory based on the assumption that 1 character equals 1 byte, it will allocate only half the required memory in Delphi 2009+, leading to buffer overflows.
    Length returns the number of elements in the string or in an array. Length for the strings with 8 bit element types (ANSI, UTF-8) gives the number of bytes since the number of bytes is the same as the number of elements, but the Length for the strings with 16 bit elements (UTF-16) is half the number of bytes because each element has 2 bytes.
    Wrong Code:
    GetMem(Buffer, Length(MyString)); // Allocates half the needed bytes!
    Correct Code
    GetMem(Buffer, Length(MyString) * SizeOf(Char));
  7. File I/O (BlockRead / BlockWrite & TStream) in reading or writing strings directly to files using raw byte streams will now write 2 bytes per character, breaking backwards compatibility with old file formats.
    Fix, if you need to save text files in traditional ANSI/ASCII format, explicitly use AnsiString or pass TEncoding.ANSI (e.g., StringList.LoadFromFile('file.txt', Tencoding.ANSI)) to TStringList.SaveToFile or TStringList.LoadFromFile.

    var LegacyStr: AnsiString; begin LegacyStr := AnsiString(MyUnicodeString); Stream.Write(LegacyStr[1], Length(LegacyStr)); end;

  8. Windows API Calls brings surprises out of (PChar casting)
    Delphi automatically maps Windows API functions to their Unicode (W) variants instead of ANSI (A) variants.
    For example: SetWindowText calls the SetWindowTextW.
    If PAnsiChar is explicitly being passed to an API that now expects PWideChar, the compiler will give error. Types must be updated to PChar to let Delphi handle it natively, or explicitly call SetWindowTextA if the ANSI is used.
  9. CharInSet appeared in Delphi 2009 to avoid warning: "WideChar reduced to byte char in set expressions". Sets in Delphi can contain a maximum of 256 elements.
    Implementation of the CharInSet function analogue for older versions of Delphi 6-2007: function CharInSet(AChar: Char; ASet: TSysCharSet): Boolean; begin Result := AChar in ASet; end;
  10. Pointer math must be reviewed: if a PChar pointer Inc(P) is incremented, it now jumps by 2 bytes instead of 1. If there is manual byte-level parsing, the pointer type must be changed to PByte or PAnsiChar.
  11. If old code used string or AnsiString as binary Data buffers to load raw binary data, encrypted data, or file streams, this will now break because the runtime will try to parse or convert invalid UTF-16 surrogate pairs.
    Change the variable type from string to RawByteString or TBytes (an array of bytes) to fix and completely bypass Unicode conversion logic.
  12. Ensure that database drivers and components are updated to versions that support Unicode data types (TWideStringField instead of TStringField if storing non-ASCII data).

Delphi 2009 has got the unit AnsiStrings.pas appeared in ..\source\Win32\rtl\common.
The ANSI function to Ansi-fy
This article will not be complete, some text was removed intentionally. If you are unable to apply this, please contact for paid consultation.
Данная статья не будет полной, часть текста была удалена намеренно. Если вам не удалось применить, обращайтесь за платной консультацией.

Delphi Version in Windows System Registry

Initially the project was made October 27, 2010 by Rodrigo Ruz
The essence of the project is to detect the Delphi (or Rad-Studio) versions installed in a system by check the existence of registry keys under the HKEY_CURRENT_USER root. Good illustration to the article Default system registry path for Delphi and C++Builder

The project was simplified, only one form was left and newer Delphi versions from XE2 up to Delphi 13 Florence were added.
The Delphi version remained the same - 2007
Checked in Delphi 2007
Date last modified: August 25, 2026

The project Delphi Version in System Registry is available in My Github Repository

TitleBar - Delphi component which adds many features: AutoHide, SetRegion, border width for form, color for everything, good looking borders, ShowInTaskbar, etc.

TitleBar - Delphi component which adds many features
This is a curiosity component demonstrates, what can be made of Delphi forms and control elements.
This is another note for Delphi code modernization trend
Changes in TTitleBar by Valient Newman in an attempt to revive an old project and to make the component meet the requirements of Delphi 6 and higher.
Corrections were tested in Delphi 2007, 2009 environment. Date last modified by Newman: January 30, 2025
Checked in in Delphi 2007, 2009
Updated January 30, 2025

TTitleBar v2.01

TitleBar - Delphi component which adds many features: AutoHide, SetRegion, border width for form, color for everything, good looking borders, ShowInTaskbar, etc.

The components TTitleBar v2.01 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. Source code is provided free of charge. The software is provided to you “AS-IS”. As such, there is no guarantee of any support whatsoever.


credits to:
Seth Taylor made this component on February 8, 1999 on Delphi 3

DFS EllipsisPanel is Delphi component that can shorten the caption text, replacing it with '...'

TdfsEllipsis Panel Demo
Delphi code modernization trend
Changes in TdfsEllipsisPanel have been made by Valient Newman to make the component meet the requirements of Delphi 2, 2009 and higher.
Checked in 2009
Updated 22 dec 2025

TdfsEllipsisPanel v1.20

DFS EllipsisPanel is Delphi component that can shorten the caption text, replacing it with '...' when it does not fit the available space. Also a generic function that "ellipsifies" a string is provided.

The components TdfsEllipsisPanel v1.20 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. All DFS source code is provided free of charge. The software is provided to you "AS-IS". As such, there is no guarantee of any support whatsoever. The component throws an Access violation error and its source code can be used as an example for study.



credits to:
Bradley D. Stowers The author of All Delphi Free Stuff (“DFS”)
Copyright 1996, Brad Stowers. All Rights Reserved.

DFS GrabBar - Delphi component, grab bar, or splitter, to allow two windows to be resized simultaneously

TdfsGrabBar Demo
Delphi code modernization trend
Changes in TdfsGrabBar have been made by Valient Newman to make the component meet the requirements of Delphi 2, 2009 and higher.
Checked in 2009
Updated 22 dec 2025

TdfsGrabBar v1.17

DFS GrabBar is a bar that allows two TWinControl components to be resized by dragging it.

The components TdfsGrabBar v1.17 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. All DFS source code is provided free of charge. The software is provided to you "AS-IS". As such, there is no guarantee of any support whatsoever.



credits to:
Bradley D. Stowers The author of All Delphi Free Stuff (“DFS”)
Copyright 1996, Brad Stowers. All Rights Reserved.

DFS MRUFileList - Delphi component to simplify adding MRU file lists to menus

TMRUFList Demo with RadStudio Delphi 2009 Closed Files list
Delphi code modernization trend
Changes in TdfsMRUFileList have been made by Valient Newman to make the component meet the requirements of Delphi 2, 2009 and higher.
Checked in Delphi 2007, 2009
Updated 21 dec 2025

TdfsMRUFileList v2.68

DFS MRUFileList - Delphi component that greatly simplifies adding MRU file lists to menus.
TMRUFList Demo was made with RadStudio Delphi 2009 Closed Files list in mdFileNameOnly.

The components TdfsMRUFileList v2.68 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. All DFS source code is provided free of charge. The software is provided to you "AS-IS", and all risks and losses associated with it's use are assumed by you. As such, there is no guarantee of any support whatsoever.



credits to:
Bradley D. Stowers The author of All Delphi Free Stuff (“DFS”)
Copyright 1996, Brad Stowers. All Rights Reserved.

MiTeC File Explorer is Windows Explorer-like component

TMFileExplorer Demo
Delphi code modernization trend
Changes in TMFileExplorer have been made by Valient Newman to make the component meet the requirements of Delphi 6 and higher.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 20 dec 2025

TMFileExplorer v1.15

MiTeC File Explorer is Windows Explorer-like component.

The components TMFileExplorer v1.15 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. All source code is provided free of charge. As such, there is no guarantee of any support whatsoever.



credits to:
Michal Mutl his GitHub
Copyright © 1999, 2003.

DFS Icon Controls: Icon ComboBox and Icon ListBox caching components for Delphi

TdfsIconComboBox Demo with Delphi 2009 icons
Delphi code modernization
Changes in TdfsIconComboBox and TdfsIconListBox have been made by Valient Newman to make the component meet the requirements of Delphi 2, 2009 and higher.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 18 dec 2025

TdfsIconComboBox and TdfsIconListBox v1.17

The caching Icon ComboBox and Icon ListBox components for Delphi.

A dropdown list style combobox that displays the icons that exist in a given file, and a listbox that displays the icons that exist in a given file, either horizontally or vertically.

TdfsIconListBox Demo with Delphi 2009 icons

Features: Optionally, the control can disable itself when the filename is invalid. Optionally, the control can load icons "on demand." This speeds up the initialization process greatly because all icons do not have to be loaded when the control is created. Many file formats can be read from, including: .EXE, .DLL, .ICO .ICL { PCTools? Icon Library .NIL { Norton Icon Library ListBox can simulate a grid of icons, allowing you to set the number of icons to be displayed in both the X and Y direction. This setting can be changed dynamically.

The components TdfsIconComboBox and TdfsIconListBox v1.17 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments. All DFS source code is provided free of charge. As such, there is no guarantee of any support whatsoever.



credits to:
Bradley D. Stowers The author of All Delphi Free Stuff (“DFS”) Copyright 1996, Brad Stowers. All Rights Reserved.

FWTrayIcon - component for registering class to work with the system tray

FWTrayIcon - component for registering class to work with the system tray demo
Delphi code modernization
Changes in TFWTrayIcon by Valient Newman to make the component meet the requirements of Delphi 2009 and higher.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 18 dec 2025

TFWTrayIcon v1.05

Сomponent for registering class to work with the system tray.

The component TFWTrayIcont v1.05 is available in My Github Repository

The component has realization issues for instance with hint display and the use of this component is on your own risk.

The software is provided as is without any garanties and warranty.
This component can be freely used and distributed in commercial and private environments.



credits to:
Fangorn Wizards Lab Exstension Library
Alexander (Rouse_) Bagel, his GitHub
© Fangorn Wizards Lab 1998 - 2005.

FWHint - component to register class to work with application hints

FWHint - component demo
Delphi code modernization
Changes in TFWHint by Valient Newman to make the component meet the requirements of Delphi 2009 and higher.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 17 dec 2025

TFWHint v1.05

Сomponent for registering class to work with application hints.

The component TFWHint v1.05 is available in My Github Repository

This component can be freely used and distributed in commercial and private environments.



credits to:
Fangorn Wizards Lab Exstension Library
Alexander (Rouse_) Bagel, his GitHub
© Fangorn Wizards Lab 1998 - 2005.

DlgTest is design-time testing of TCommonDialog component descendants

CodeGear Delphi 2007
Delphi legacy code modernization
Corrections brought in DlgTest by Valient Newman to make the component meet the requirements of Delphi 6, when the design-time and runtime code must be separated.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 17 dec 2025
The component DlgTest is available in My Github Repository This component can be freely used and distributed in commercial and private environments.

DlgTest v1.05

Design-time testing of TCommonDialog component descendants.
credits to :
Bradley D. Stowers The author of All Delphi Free Stuff ("DFS")
Copyright 1996, Brad Stowers. All Rights Reserved.

DFS Color Button

Delphi legacy code modernization
Corrections brought in CBtnForm, ColorAEd, DFSClrBn by Valient Newman to make the component meet the requirements of Delphi 2, 2009 and higher, where WinTypes, WinProcs units are absent.
Checked in Delphi 7 and Delphi 2007, 2009
Updated 15 dec 2025

TdfsColorButton v2.62

A Windows 95 and NT 4 style color selection button, which displays a palette of 20 color for fast selection and a button to bring up the color dialog.

This component can be freely used and distributed in commercial and private environments.

The component DFS Color Button is available in My Github Repository



credits to :
Bradley D. Stowers The author of All Delphi Free Stuff ("DFS")
Copyright 1996, Brad Stowers. All Rights Reserved.

Delphi 2007 and Delphi 2009+ difference in string types. Migration

CodeGear Delphi 2007

This is not a divine revelation, but simply semblance of my personal reference.

In Delphi 2007, AnsiString was the default string type used for general-purpose string manipulation.
This means variables declared simply as string were compiled as AnsiString. This changed in Delphi 2009+, where string became an alias for UnicodeString.

AnsiString in Delphi 2007:
  • In Delphi 2007 Char was an 8-bit (1-byte) AnsiChar, while in Delphi 2009+, it became a 16-bit WideChar (UTF-16) by default.
  • Encoding: The interpretation of these bytes depends on the operating system's current active code page (e.g., Windows-1252, or specific locales like code page 936 for simplified Chinese).
  • Length: AnsiString was dynamically allocated and limited only by available memory, unlike the older ShortString that was limited to 255 characters.
The primary distinction in Delphi 2009 and later is the shift to Unicode.
  • Char now represents a 16-bit character, enabling full Unicode support. Char becomes WideChar
  • string is an alias for UnicodeString (UTF-16, 2 bytes per character).
  • AnsiString still exists but is used primarily for backward compatibility or interfacing with non-Unicode systems/APIs.
When moving from Delphi 2007 to Delphi 2009 (or later):
  • AnsiString to UnicodeString: String changes, leading to potential data loss if ANSI data is assigned directly to Unicode strings.
  • Explicit Casts: Use PAnsiChar(myWideString), AnsiString(myUnicodeString) and similar, where needed, and be aware of character mapping.
  • Migration Required: Code using Char, PChar needed updates, especially with assignments between ANSI and Unicode types.
  • If a 1-byte buffer is in need, use RawByteString instead of string or Char. RawByteString is AnsiString with no code page set by default (AnsiString($ffff)).
(e.g., #128 isn't the Euro sign in Unicode).
Delphi and Unicode, Marco Cantù, December 2008

Windows 64bit Delphi 2007/2009 Debugger Fix / Workaround with "Assertion failure" error

«SetThreadContext failed» Delphi 2007/2009 Windows x64
This error is typical not only for 7, but also for subsequent Windows 64-bit. Delphi 2007 and 2009 are susceptible to the "Assertion failure" error.
If one run Delphi 2007 or Delphi 2009 on Windows 64bit and met the Assertion failure when hit F2 or exit out of the program, this strange error dialog occurs: bds.exe - bordbk105N.dll Assertion failure: "(!"SetThreadContext failed")" in ..\win32src\thread32.cpp at line ... Continue execution? If Press No or ESC key will close the whole IDE. Pressing Yes may prompt for the same dialog.

There was an unofficial hotfix at CodeCentral - ID: 27521, RAD Studio 2007 Debugger Fix for Windows 7 that now is unavailable.

Further is a temporary solution for this problem.
Using any hex editor, for example, mh-nexus, an open source version.
1. Close Delphi
2. Make a backup of the library bordbk105N.dll (version should be 105.11.1.12533) for Delphi 2007, bordbk120N.dll (version should be 120.903.17.15115) for Delphi 2009
For Delphi 2007
the location is "%ProgramFiles(x86)%\CodeGear\RAD Studio\5.0\bin\bordbk105N.dll",
for Delphi 2009
the location is "%ProgramFiles(x86)%\CodeGear\RAD Studio\6.0\bin\bordbk120N.dll"
3. Open the library file in hex editor
4. Look for hex string in the file
01 00 48 74 47 80 3d
There is only one(!) HEX 01 00 48 74 47 80 3D
5. Change it to
01 00 48 EB 47 80 3d
74 is replaced with EB
6. Save
7. Restart Delphi and the error message should be gone. That’s all. Now the debugger runs on Windows 64bit.

Or try to find the in the internet the ready-to-use patcher Delphi_2007_2009_WOW64_Debugger_Fix.zip (Delphi_2007_2009_WOW64_Debugger_Fix.exe) who will do the same for you.

CodeGear Delphi 2007
My first note was «SetThreadContext failed» Delphi 2007/2009 Windows x64.
Here I made more detailed explanation.
An put a concise version of the article on Stackoverflow

TBytesStream class for Delphi 2007

CodeGear Delphi 2007
TBytesStream class was added in Delphi 2009, so I define it manually for CodeGear Delphi 2007. type TBytesStream = class(TMemoryStream) private FBytes: TBytes; FCapacity: Longint; FSize: Longint; protected function Realloc(var NewCapacity: Longint): Pointer; override; public constructor Create(const ABytes: TBytes); overload; property Bytes: TBytes read FBytes; end; Full unit published on Github

ZEOS Library 8.0.0 does not support Delphi 2007 and older

ZEOS Library
A file ZBase64.pas appeared in the ZEOS Library 8.0.0 in folder with path "src\core\" that can not be compiled.
The class TBytesStream in ZBase64.pas was added in Delphi 2009.

SqlitePass support for the Rad Studio Delphi 2007

CodeGear Delphi 2007
This my addition gives the support for Rad Studio Delphi 2007 to SqlitePass and quite possible to Delphi 2005, 2006.
The most significant processing has been made to the file SqlitePassDbo.inc
Published on Github

Delphi 2007 - Error creating form: Failed to set data for...

CodeGear Delphi 2007
The error message like this - "Error creating form: Failed to set data for..." appears on IDE CodeGear Delphi 2007 startup.
This situation occurs due to lack of access rights.
A simple and obvious half-measure is to run IDE CodeGear Delphi 2007 with administrator rights.
For example - check "Run this program as an administrator" in the "Compatibility" tab in Properties menu.
Delphi 2007 - Error creating form: Failed to set data for...

Unable to load project in Delphi 2007. Only one top level element is allowed in an XML document

CodeGear Delphi 2007
Loading the project .dproj file created in a newer Delphi that older Delphi 2007 version can cause such an error:
"Only one top level element is allowed in an XML document"

There is the requirement for XML document to have exactly one root element.
The error informs that ".dproj file" which is the document in XML format does not adhere to this requirement and thus malformed.
Perhaps, the .dproj file has been corrupted.

Unable to load project in Delphi 2007. Only one top level element is allowed in an XML document
The most expedient way to solve this issue is to remove the .dproj file, launch the correspondent .dpr file and let the IDE regenerate one.
If the matter is with dpk file, the way to solve is to create an empty package and import the files in.