r/delphi • • 7d ago

Project Delphi to C#/C++ migration: Are traditional code converters still useful in the age of AI?

I have been developing rule-based Delphi source code converters for many years, including Delphi2Cpp and Delphi2C#.

Recently, I published a free Delphi-to-C# converter, D2CSharp, together with a Delphi-compatible C# runtime library on GitHub:

https://github.com/dm-e/D2CSharp

I have just released a substantial update with improvements to the converter, additional RTL functionality, and more tests.

D2CSharp can be used free of charge to translate your own Delphi code. The runtime library is open source, and contributions are very welcome. The converter itself is distributed as a free executable, but its source code is not included.

However, I would also like to start a broader discussion.

Does it still make sense to develop traditional source code converters now that AI can translate code?

I am not interested in reopening the general debate about whether migrating away from Delphi is a good idea. That has been discussed many times.

Instead, I am interested in the practical question: Once a developer has decided to migrate an existing Delphi application to C# or C++, what is the best approach?

Traditional rule-based converters aim to produce consistent and reproducible translations. AI offers different possibilities, particularly when restructuring code or replacing Delphi-specific constructs with native features of the target language.

But how do these approaches compare when converting larger projects with many interconnected units, complex types, pointers, and dependencies on the Delphi RTL?

Can AI alone handle such migrations reliably, or is there still a useful role for dedicated converters, possibly combined with AI-assisted refactoring?

I would be particularly interested in hearing from developers who have actually attempted such migrations.

What worked, what caused problems, and which approach would you choose today?

And if you are interested in experimenting with D2CSharp or contributing to its free runtime library, you are very welcome to join the project.

3 Upvotes

9 comments sorted by

1

u/rmagnuson 6d ago

If you're doing a 1:1 conversion, presumably because they're both OO languages, do you still get the same efficiency in the target language? I would imagine that AI has the ability to extrapolate from the code that is fed to it and come up with a refractor that takes into account any little tricks that a Delphi Dev might use to get better performance and translate those to the target language. Just a thought.

2

u/Delphi2C 6d ago

That's a good point. The efficiency of the translated code depends very much on the kind of code involved. Ordinary application logic may perform similarly to the original, while some Delphi-specific features, particularly pointer simulation and mutable strings, can introduce considerable overhead in C#.

For me, the first priority is to get the entire codebase translated into a consistent form while preserving its original behavior. Optimization and refactoring can come later.

The Delphi RTL is a good example: D2CSharp initially generates mock implementations for missing RTL functions, which can then be replaced with proper C# implementations, potentially developed or optimized with the help of AI.

I agree that AI has advantages when it comes to restructuring code and making better use of the target language. But such transformations also carry the risk of unintentionally changing the program's behavior.

That's why I think combining systematic translation with AI-assisted optimization and refactoring could be particularly useful.

I'd be particularly interested in hearing from developers who have used AI to translate or refactor larger codebases. What worked well, and where did you encounter difficulties?

2

u/Nervous_Wind4216 5d ago

I did.

For a 450k lines project. About analysis and calculations. Using only AI, it took about a week for a first ugly prototype, and two months later, full version production ready with more features, improved logic, 4000+ new unit tests written, faster 3d, etc name it you know the rest. Burn rate was about 8h/day. About 55 work days total. Cost 500$ in AI tokens.

AI need boundaries, guides, do's and don'ts for the coding standard, verbosity in variables naming, architecture, tests, granularity, code comments, instructions, etc before starting anything. I had to budget one or two days first in analysis and structuring how things should go before starting anything.

During our porting, it founds about 30 serious typo errors on 20k lines files that would have been directly translated otherwise. It fixes bad architectures we had to live with previously too. Sometimes, porting a software also allow some refactoring among the way. Like, "yeah by the way, when you will port those 3d rendering forms in c#, keep in mind that delegates will be calling some refresh methods to modify the 3d images".
"While porting, have centralized localization files, font size and types among other global parameters that we might need to tweak later". "Ah also, while porting, convert png images to svg if you can" -- or whatever format.

"Oh AI, while porting, keep that off the main thread for as smoother UX".

For me it was priceless.

And because we still had the Delphi and the ported app running at the same time, we were able to compare analysis results, reports, modelling and [insert something here] in between; and it saved the day many times too. Comparing form, reports, analysis, charts, graphs between the original and the new code did last for 3 weeks kind of, on the side. And it's now a copycat to the pixel. AI can take screenshot, see both versions of your app, and adjust.

If a VCL component is too specific, you need to instruct AI to either find an alternative or to build its own. 2 hours later and you have it, potentially improved.
Your mileage will vary of course. And I'm sure that the converter product above is awesome and everything but, even if I had to use an above converter, I would then ask AI to make another pass in the converted code for optimization, refactoring, commenting, and all the rest above.

Another strong point, in my perspective of course, is that while AI is doing his stuff, you have time to think about the future, think about the what's next, how to improve your product, to add better features, to focus on the next step. And that, for me still, it's also an enormous gain -- but out of the subject sorry.

My two cents :)

1

u/Delphi2C 5d ago

Thank you for this detailed report! This is exactly the kind of real-world experience I was hoping to hear about.

Migrating 450k lines of Delphi code using AI alone is impressive, especially since you also took the opportunity to improve the architecture, fix bugs, and add extensive tests.

You mentioned comparing the original Delphi application with the ported version. A largely 1:1 translation makes this possible at an even more detailed level: both applications can be debugged side by side, stepping through corresponding code and comparing intermediate results. This can be particularly useful for complex calculations. Another advantage of a rule-based converter is that it systematically processes the entire source code, making it easier to ensure that nothing is overlooked — something that may be more challenging with AI-based translation.

I'm especially interested in how you organized the migration of such a large codebase. Did you work through the Delphi units individually, or did you use an AI tool that could analyze and process the entire project, including dependencies between units?

And since you mentioned migrating forms and 3D rendering, which C# GUI framework did you choose? D2CSharp doesn't currently translate the GUI, so this is particularly interesting to me.

Finally, which AI tools or models did you use?

And by the way, traditional converters also leave you time to think about the future — just not quite as much. :)

1

u/Nervous_Wind4216 5d ago

You are right with a traditional converters. Converting method-by-methods would have probably save some debug time. I did use Claude Code for the whole project, and still today.

My approach was:
- ask for a whole project analysis
- split core sections: Core logic, calculations and analysis, forms, tests, IO's related.

- then create sub plans or sub projects section for each core sections. Ex: IO's : load config, save config, load project file, save project file, tests, what if's, report exporting, report importing, 'save as' features, exporting in other formats, etc.

- don't forget to tell the agent to keep track of his own progression. Windows rebooting, closing the window by mistake, electrical downtime it can all occurs and we want to continue were we left off as easiest as possible.

- ask the agent to build a plan that can be given to other sub agents. Some task are sharable among sub agents, improving speed and blowing tokens. Sub agents could also be more simpler for easier task and lower the costs.

- then I've reviewed the plan, asking questions like 'have you thought about this or that, project files are encoded json, don't forget about multi language support, keep in mind that too specific Delphi library might exist in other open source variations, try to keep external dependencies as low as possible, why are you proposing that approach vs another one...' and so on.

- you also instruct the agent to take some notes of his findings, observations or stuff postponed to be dealt later with a human; observations, bugs, typo's, recommendations etc.

Then two-three weeks later, start the verification process. Comparing apps side by side, taking screenshot and telling the agent : hey you did miss that, images aren't shown correctly, this label is truncated, help button is not working etc.

I re-read my self this morning and I didn't want to sound rude; I do embrace new ideas, different approaches, software developers like you. AI is currently awesome but it doesn't fix everything and I do favors humans first. We are using C# WinForms and OpenTK for the GL stuff.

As I recall, Claude first we translated .frm files into utf8 .frm files (not binary), then he ended up creating a python script that did translate objects into 'in line objects creations'. On our final weeks, I had to told Claude to disconnect the dependency of the original .frm files, and convert them to .cs designer files that we could tweak one day. Took a day to process if I recall correctly.

1

u/Delphi2C 5d ago

Thank you for taking the time to explain your approach in such detail!

I didn't find your comments rude at all. On the contrary, this is exactly the kind of open and constructive discussion I was hoping for.

It's particularly interesting that Claude ended up generating a Python script to systematically convert the Delphi forms. In a way, AI created its own specialized converter for that part of the migration. :)

Your experience gives me quite a bit to think about regarding the future development of my own converters.

Thanks again for sharing!

1

u/Nervous_Wind4216 4d ago

You are welcome :)

1

u/CriteriumA 5d ago

From what to what did you migrate the project?

1

u/Nervous_Wind4216 5d ago

Delphi Windows app, about 135 forms to C#.