cd /news/ai-agents/6-delphi-behaviors-that-silently-bre… · home › topics › ai-agents › article
[ARTICLE · art-173797] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

6 Delphi behaviors that silently break when an AI ports your code to C#, Java or C++

A developer built Delphi Behavior Contracts, a bilingual English/Russian reference of 74 chapters and 89 directive cards documenting Delphi semantics that AI code-porting agents silently get wrong when translating to C#, Java or C++. Measured on the Delphi 13 compiler across 879 build observations and 650 runs on Win32 and Win64, it covers traps such as banker's rounding, 1-based string indexing, value-versus-reference array copying, interface lifetime destruction and the platform-dependent Extended type. It ships as a Claude Code plugin, a plain skill for other agents, and an offline MCP server listed in the official MCP Registry as io.github.DIIIUA/delphi-behavior-contracts.

recommendation

When porting Delphi with coding agents, give them a measured behavior reference covering rounding, indexing, copy semantics and type widths instead of relying on the call site alone.

more in playbook: Working with AI coding agents
by read2 min views4 publishedNov 21, 2026

AI agents are good at producing code that compiles. With Delphi, "compiles" and "behaves the same" are far apart. Here are six behaviors I keep seeing agents get wrong — each one is measured on the Delphi 13 compiler, not recalled from memory.

Round is banker's rounding Round(2.5) = 2 and Round(3.5) = 4 in Delphi: halfway cases go to the nearest even number. C#'s Math.Round does the same by default, but Java's Math.round(2.5) and C++'s std::round(2.5) return 3. A port to Java or C++ that maps Round to the "obvious" function changes every halfway result.

If the last unit in uses declares its own Round, an unqualified Round(2.5) calls that one, not System.Round. An agent that reads the call site alone will port the wrong function. S[1] is the first character of a Delphi string. Off-by-one errors appear in every loop and Copy call that is translated literally to 0-based indexing.

B := A copies a static array or a record by value; changing B leaves A alone. In C# and Java arrays are references, so the "same" code suddenly shares data. Dynamic arrays (array of T) behave the other way: they are shared until you call SetLength or Copy.

When an object that implements an interface is held both through an object variable and an interface variable, the object is destroyed as soon as the last interface reference goes away. The object variable is now dangling. In a garbage-collected target this whole class of bug disappears — and so does the behavior the original code depended on.

Extended is not the same type on every target Extended is 10 bytes (80-bit x87) on Win32 and 8 bytes (an alias of Double) on Win64. The same source produces different floating-point results on the two targets, which matters when you compare a port against a 32-bit legacy build.

I turned these and many more behaviors into Delphi Behavior Contracts: a bilingual (EN/RU) reference of 74 chapters and 89 directive cards, measured on Delphi 13 (879 build observations, 650 runs on Win32 and Win64). Questions the documentation does not settle are listed by name instead of being guessed.

It installs as a Claude Code plugin, a plain skill for other agents, or an offline MCP server (it is in the official MCP Registry as io.github.DIIIUA/delphi-behavior-contracts).

If you port or maintain Delphi code, I would like to hear which traps your agents still fall into.

── more in #ai-agents 4 stories · sorted by recency
── more on @delphi 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/6-delphi-behaviors-t…] indexed:0 read:2min 2026-11-21 · —