Best way to convert Delphi 6 code to C#

As the title says, I'm looking to convert as much Delphi code to C# as possible.  

I realize there are some tools that will convert whole projects.  I'm thinking this may not be the best way.  Maybe file by file or function by function.  I don't need the designer code converted although having the control names identical to the new C# designer would probably be helpful.

Control names aside, what is considered to be the best solution for people needing such conversions?

Who is Participating?
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
The best solution, no matter what language you come from, is to rewrite the application.

Conversions between 2 different .NET languages, say VB.NET to C# can give usable results, because they fundamentally use the same system and the same paradigms. It's only a question of converting the syntax.

However, when you come from a completely different environment, simply adjusting the syntax is not enough. Even trying to convert from VB6 to VB.NET is never a good solution, although the syntax used is the same.

If you look at it closely, Delphi (Pascal) and C# do not do much in themselves. The work is mainly done in classes that they use. The classes in Delphi are not the same as those in C#. And this is where conversions cannot do a good job. A button in Delphi is not the same as a button in C#. They do not have the same properties and methods. Although some can be simply mapped by the converter, many exist in one environment and not in the other one. Same thing for the file I/O classes and the database access classes.

Same thing for all the classes that your application uses.

After the converter has done its job, you are stuck with a lot of code that could not be converted. And the code that could be is not efficient. In order for the application to work as closely as it was doing before, the converters often need to generate a dozen lines of code to reproduce in .NET something that was done in one line in the old environment. Usually, when you code straight in .NET, it's the reverse.

The generated code is thus incomplete, is a mess, a nightmare to debug, and a very bad way to learn how to do things in the framework.

As a .NET trainer, I have witnessed many tries at converting older applications to .NET, from different languages and environments, and almost all of those fell flat, sometimes after days or weeks trying to make the thing works. In most cases, after losing much time, the conversion project is scrapped, and the application either left in its old format or rewritten from scratch.

The very few conversions that do eventually reach production are usually buggy and/or unstable, and are always a pain to maintain.
lenordisteConnect With a Mentor Commented:
I agree with jamesburger, a rewrite is probably the best way to go!

Also, you while it is tempting to convert this project file by file and function by function, this process will probably yield an "old application written with a new language". Best approach is to document what you need from this application and write it anew. This will help get rid of legacy code or features which may not even be useful anymore! The worst thing is to spend time coding/thinking about how to rewrite a piece of code while the goal is to arrive at the same result, and not the how. The time you'll save going this route will probably leave you with some free time to tweak it further or add new wanted features.
John500Author Commented:
Well, thanks to both of you.  I didn't know whether such a tool would at least give me some insight but I can see now it wouldn't be good.

We're talking about a Form Application that has six tabs numerous text boxes, a menustrip, tool strip etc.  The folks that asked me to convert it say it should take about a month.  I don't know.  

Just started working at this place.  I was hoping to utilize some code reuse because they have already converted numerous similar applications.  Nobody gives code away these days except here... or I keep getting the wrong jobs.
Jacques Bourgeois (James Burger)PresidentCommented:
You can think of code reuse if the applications where designed as forms in a .exe and most of the functional code in dlls.

You could then rewrite the forms in .NET and simply connect to the old dlls. This works pretty well if the dlls were designed properly.

But if the applications were big .exe that contains everything, a conversion is not something I would consider.
John500Author Commented:
Thanks again!
All Courses

From novice to tech pro — start learning today.