Net-Base Magazine

19.04.2026

Unicode Migration of Legacy Delphi Projects: Pitfalls, Strategy, and Clean Implementation

Unicode migration of legacy Delphi projects is not a recompile: decisive are system boundaries, encodings as a data contract, and round-trip tests for files, DB, WinAPI and DLL/COM. This scenario analysis presents hotspots, the approach and rollout questions without operational surprises.

19.04.2026

From magazine topic to project implementation

Relevant service and technical pages for this post

Monday morning, 08:30: A ticket lands with IT and Operations. “Since the last update, names in the export file are corrupted.” Attached is a CSV that appears as question marks at the recipient. Internally the list still looks “almost correct”, but in complaint handling “almost” is not enough: A misencoded character can make a record unfindable, bypass duplicate checks, or turn a dispatch process into manual exception cases.

At such moments one often hears a sentence that sets the direction: “It’s just Delphi — we only need to switch to Unicode.” The less helpful reaction is to turn this into a recompile project: new IDE, compile once, dismiss warnings, done. The better response treats the Unicode migration of legacy Delphi projects as a data and interface issue: Where do bytes become text? Which encoding is authoritative there? And how do we prove with tests that import, persistence, and export do not lose characters in transit?

This article follows that exact scenario analysis: it highlights the decisive moment, compares two response patterns, and then shows an approach that remains plannable for IT management, admins, and project owners. The focus is on enterprise applications with databases, file exchange, Windows APIs, DLL/COM interop, reports, and rollout issues — not framework internals.

Unicode migration of legacy Delphi projects in practice

Many legacy projects originate from Delphi versions where string was effectively an ANSI string: the actual character encoding depended on the Windows system codepage. Since Delphi 2009, string is by default a UnicodeString and uses UTF‑16 internally (specifically UTF‑16LE). At the same time Char and PChar change semantically: from 8‑bit (AnsiChar/PAnsiChar) to 16‑bit (WideChar/PWideChar). Embarcadero describes this break explicitly and points out that the compiler issues additional warnings for risky casts and “downcasts” to ANSI types[Quelle].

For operations this initially sounds like a programming detail. In practice it is an architectural and risk lever: as soon as “text” is handled as bytes somewhere (buffer, stream, file, protocol, hash), a system can continue to run after the change — and still silently alter data. Such errors rarely announce themselves immediately. They surface as “partner import fails”, “search does not find a record”, “PDF report shows boxes”, “address validation fails for certain names”.

The decisive moment: Not the compiler, but the system boundary

When planning a Unicode migration, you do not have to treat every code path the same. The effort almost always sits at the edges: where data enters, exits, or is handed over to another technology. This perspective is the basis for a reliable effort estimate: you look for hotspots, not “everything”.

Hotspot 1: files and streams (CSV, EDI, reports, logs)

File I/O in legacy applications is often „historically pragmatic“: text is written without specifying an encoding; on read it is assumed that „it will be fine.“ In ANSI environments that was often the system code page (e.g. Windows-1252). After the transition, libraries and routines make decisions depending on the variant about BOM (Byte Order Mark), default encodings or implicit conversions. The result is rarely a clean crash — more often a partner that can no longer import the file, or an import that replaces characters.

Important for project owners: file formats are often contractual interfaces. If a partner expects „ISO‑8859‑1“ or „Windows-1252“, UTF‑8 may be widespread technically but operationally constitutes a breaking change. In that case it is not a „bugfix“ but an interface release requiring coordination, tests and a schedule.

Hotspot 2: Database access, field types and „text as bytes“

„The database already supports Unicode“ is often only half the truth. Many systems have evolved over years: different drivers, changing databases, mixed fields (VARCHAR/NVARCHAR), varying collations/charsets. Additionally, legacy databases frequently contain text in BLOB/memo fields because it used to be simpler to „put bytes in, get bytes out.“ Those exact fields are critical in Unicode projects: the application then does not know whether the bytes are Windows-1252, UTF‑8 or something else.

The practical implication for operations and administration: plan DB roundtrip tests (write/read) for the columns and formats that are actually used. Without these tests the migration may appear „okay“ at acceptance — until an edge case surfaces in production.

Hotspot 3: Windows-API, PChar, buffer sizes

Many Windows APIs exist as an ANSI variant (suffix A) and a Wide variant (suffix W). Unicode-Delphi works by default with wide strings. Legacy code, however, sometimes explicitly calls the ANSI variant — or calculates buffer sizes in bytes even though the API counts in characters. Typical operational failure modes: truncated paths, incorrectly read registry values, sporadic access violations, problems only with long paths or „unusual“ characters.

Embarcadero describes precisely this class as an „idiom“ problem: much continues to work after the Unicode transition, but established patterns such as pointer arithmetic, casts or SizeOf/Length confusions must be checked deliberately[Quelle]. The limitation of that source: it does not replace a project audit. The conclusion is nevertheless clear: WinAPI calls belong on a verifiable list, not in „it will be fine.“

Hotspot 4: DLL imports, COM/ActiveX and third-party components

Many digital enterprise solutions depend on components that do not come with the Delphi compiler: scanner/scale integrations, signature components, print SDKs, legacy ActiveX controls, Office automation, proprietary DLLs. These interfaces are often byte-oriented (ANSI/UTF‑8) or expect BSTR (COM/WideString). After migration, errors do not necessarily appear at compile time but in semantics: the call succeeds, but data arrives incorrectly at the recipient.

For planning, a sober classification helps: „Unicode-capable“, „ANSI-only“, „unclear“. „Unclear“ is not a minor leftover but a distinct risk. If that block is large, an early technical test on the critical libraries must be prioritized.

The better response: Establish encodings as a data contract

The most stable guideline in Unicode projects is surprisingly simple: work internally consistently with Delphi-„string“ (UTF-16) and consciously define at system boundaries which encoding applies externally. Often that is UTF-8 (web, JSON, many modern tools). Sometimes it is a defined legacy code page because a partner format or a device requires it. The decisive factor is not „modern vs. old“, but „explicit vs. implicit“.

Why this matters for administrators and operations: when encodings are documented as a contract, you can test errors reproducibly (compare bytes, perform roundtrip tests) and build support processes (checklist per interface). Without a contract, encoding remains a guessing game, and every ticket starts from zero again.

Trade-off: UTF-16 internally, UTF-8 externally (and legacy where necessary)

Area Pragmatic choice Benefit for operations & acceptance Typical pitfall
Internal domain logic, UI, validation string (UTF-16) Fits RTL/VCL; fewer corner cases in the core Byte-oriented routines (hashing, streams) mistakenly implemented with string
REST/JSON, webhooks, portal integrations UTF-8 (bytes) Interoperable, easy to test and debug (payloads) „string-based“ streaming without a fixed encoding definition
Partner files (CSV/EDI), legacy devices Defined code page (e.g. Windows-1252) Contract-compliant, minimizes breaking changes Silent conversion without versioning/example file
DLL/interop Per specification (ANSI/UTF-8/UTF-16) Allows error diagnosis (clear expected value) Incorrect pointer types or wrong buffer sizes (characters vs. bytes)

A constructed example: When „just one export“ becomes an incident

An approach that remains predictable: Hotspots first, refactoring later

For IT management and project control the most important question is rarely “how” in the code, but “how do we control risk and effort”. A practical model is a staged migration that first secures system boundaries and only then addresses larger internal changes. This reduces the likelihood that you will still be dealing with “mysterious special characters” at go‑live.

Sequence of steps for a Unicode migration with robust acceptance

  1. Inventory of system boundaries: List of all file imports/exports, DB connections, DLL/COM integrations, network protocols, print/reporting paths, log/audit outputs.
  2. Define encoding and data contract per boundary: Expected encoding, BOM rules, field lengths in characters vs. bytes, behavior for “not representable” (error, replacement character, abort).
  3. Classify third-party components: Unicode-ready, ANSI-only, unclear. For “unclear”: early tests with realistic data before large code areas are adjusted.
  4. Create adapters and central conversion points: File I/O, REST-payloads, WinAPI calls, interop. Goal: conversions are discoverable, reviewable and testable.
  5. Define roundtrip tests: Problem character set plus real data flows: Import → Processing → Export, DB write/read, partner verification in a test environment, where possible.
  6. Roll out iteratively: First stabilize core + critical boundaries, then follow with modules. Each wave ends with acceptance and a fallback option (rollback plan).

Typical error classes — and why they are particularly costly in operations

Unicode issues are rarely spectacular. That is precisely what makes them costly: they behave like sporadic data quality issues that bounce between line-of-business, operations and IT. Three error classes occur particularly often in migrations.

1) Length and size errors: character length is not byte length

In ANSI applications the temptation was strong to use “Length” as a byte measure. In UTF‑16 this is no longer reliable: storage requirements and character count diverge, and certain characters involve additional encoding steps. In operation this shows up as “truncated data”, “errors only with long names” or “sporadic exceptions” in components that size buffers incorrectly.

Practical guardrail for the architecture: as soon as bytes are required (hashing, signatures, protocols, streams), code should be byte-oriented (byte arrays), and the Text→Bytes conversion belongs at a defined system boundary — with documented encoding.

2) Implicit conversions: they appear to work, but alter content

Delphi converts between string types often implicitly. That is convenient, but risky when code pages are unclear or characters are not representable. Embarcadero points out in the migration documentation that conversions between string types/code pages can result in data loss and that UnicodeString is fixed to UTF‑16LE[Source]. The limitation: that does not state which encoding your partner expects. The practical consequence: conversions belong in adapters, not scattered through business logic and the UI.

3) Inconsistent system boundaries: clean inside, inconsistent at the edges

Many legacy applications have multiple outputs: CSV for partner A, XML for partner B, REST to a portal, print output via a report engine. If each boundary is „accidentally“ encoded differently, operational reality emerges: the helpdesk has no clear checklist, and the errors are reproducible only for individual files or specific data sets.

Organizational consequence: encoding rules belong in the system documentation — not as a theoretical chapter, but as an interface table (format, encoding, field length rules, example file/payload, test case, owner, monitoring note).

Rollout and rollback: what is often overlooked during production migrations

A Unicode migration is rarely a pure refactoring. It can change data artifacts: export files, logs, possibly database columns, or sort/comparison behavior under certain collations. Therefore the migration needs a rollout design that fits your operational reality.

Concrete points that should be clarified before cutover

  • Partner communication: Which file interfaces have contractually defined encoding? Who can test against a staging environment, who needs reference files?
  • Parallel operation: Do the old and new versions need to run in parallel for a time (e.g. remote sites, terminal server farms)? Then exchange formats and data states are particularly sensitive.
  • Rollback capability: Can you revert in case of errors without already generated files/data becoming unusable? (For example: which exports have already been sent?)
  • Monitoring: Where can you quickly see that an import suddenly produces more errors or that a partner interface has increased? Which logs are suitable for encoding diagnosis?

Clear boundaries: when Unicode is not the main problem

Unicode does not automatically resolve structural legacy burdens: outdated data access layers, 32‑bit limits, missing test coverage, historically grown interfaces without contractual definitions. In some projects Unicode is more the trigger that reveals a driver or a library does not have a clean Unicode chain. Then the migration becomes the catalyst for larger modernization (e.g. data access or interface consolidation). That can be sensible — but should be made as a deliberate scope decision, not as something that „just happens.“

And another often overlooked point from domain logic: not every value needs to be „freely international.“ Identifiers (customer codes, article numbers) should ideally remain deliberately ASCII‑close, while free text (names, addresses, comments) must be Unicode-capable. This separation reduces side effects in sorting, search, duplicate-detection logic and interface validation.

Conclusion from the scenario analysis: Recompile is the wrong target

In the opening scene the decisive moment was not the update of the Delphi version, but the question: „Which encoding applies at which boundary — and how do we demonstrate that nothing is lost?“ The less helpful response („it compiles“) makes the migration appear faster, but shifts the real costs to operation and support. The better response is a controlled program: inventory hotspots, define encoding rules as a data contract, centralize conversions, build roundtrip tests and plan the rollout so that rollback and partner acceptance are possible.

If you want to assess the Unicode migration of legacy Delphi projects at your organisation as part of a modernization path (interfaces, data storage, third-party components, rollout), this can be clarified most quickly in a structured initial consultation: Contact us.

Sources and further information

The technical core statements were editorially contextualized based on the following external sources.

  1. Unicode in RAD Studio – RAD Studio (docwiki.embarcadero.com)
    Since Delphi 2009, string is UnicodeString (UTF‑16) and Char/PChar behave accordingly; migration generates additional warnings for risky casts.
  2. Delphi in a Unicode World (www.embarcadero.com)
    Many applications continue to work after the switch, but typical legacy idioms (casts, pointer/size logic, assumptions about strings) must be specifically reviewed and adjusted.
  3. Delphi Unicode Migration for Mere Mortals: Stories and Advice from the Front Lines (d2ohlsp9gwqc7h.cloudfront.net)
    Conversions between string types/code pages can cause data loss; UnicodeString uses UTF‑16LE by default — encoding decisions must be made consciously.

For this topic, Delphi Ansi to Unicode and Delphi string types are also important. The article contextualizes these aspects clearly and shows what matters in everyday operations.

Discuss a project or modernization initiative with Net-Base.

Next step

When the topic becomes an actual project, architecture, existing systems and operations should be considered together from the outset.

We support not only with individual issues, but also when source snippets, legacy topics, or portal ideas are to be turned into a robust enterprise project.

  • Current state, target state and technical risks are assessed jointly.
  • REST, data access, portals and rollout are not deferred to a later stage as secondary consequences.
  • You can see early on which path is economically and operationally viable.

Share post

Share this post directly

LinkedIn, X, Facebook, WhatsApp und E-Mail sind sofort verfügbar. für Instagram bereiten wir Link und Kurztext direkt vor.

Email

Instagram opens in a new tab. The link and short text are copied to the clipboard beforehand.

Write comment

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert