有哪些工具可以将 Delphi 7 应用程序转换为 C# 和 .Net 框架?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 10:18:18  来源:igfitidea点击:

What tools exist to convert a Delphi 7 application to C# and the .Net framework?

提问by devstopfix

I maintain an old PC-only application written in Delphi 7. Although Delphi has served me very well in the past I now only use it for this one application and find my skills with the language diminishing. Its syntax is too different from my 'day job' languages of Java/Ruby so it takes me longer to get into the groove of writing new code, plus it is so old I have not used many interfaces so the code is not managed which seems ancient to me now!

我维护着一个用 Delphi 7 编写的旧的仅限 PC 的应用程序。虽然 Delphi 过去为我提供了很好的服务,但我现在只将它用于这个应用程序,并且发现我的语言技能正在下降。它的语法与我的 Java/Ruby 的“日常工作”语言差别太大,所以我需要更长的时间才能进入编写新代码的最佳状态,而且它太旧了我没有使用过很多接口,所以代码没有被管理现在对我来说似乎很古老!

Many of my users are moving to Vista which may run the app in compatibility mode or may have GPF problems depending on how their PC is configured by their IT department, so I have to do some maintenance on the application. I'm wondering if I should jump to a more familiar stack.

我的许多用户正在迁移到 Vista,这可能会在兼容模式下运行应用程序,或者可能存在 GPF 问题,具体取决于 IT 部门如何配置他们的 PC,因此我必须对应用程序进行一些维护。我想知道是否应该跳到更熟悉的堆栈。

Is there an automated tool that will do the legwork of converting the code base to C#, leaving me to concentrate on the conversion on any non-standard components? I'm using an embedded database component called AbsoluteDatabasewhich is BDE compatible and using standard SQL throughout, and a native Delphi HTML browser component which can be swapped out with something from the Microsoft world.

是否有自动化工具可以完成将代码库转换为 C# 的工作,让我专注于任何非标准组件的转换?我正在使用一个名为AbsoluteDatabase的嵌入式数据库组件,它与 BDE 兼容并始终使用标准 SQL,以及一个本机 Delphi HTML 浏览器组件,它可以与来自 Microsoft 世界的东西交换。

How good are these conversion tools?

这些转换工具有多好?

采纳答案by Jim McKeeth

I am not aware of any automated tools for making that conversion. Personally I would suggest you stick with Delphi, maybe just upgrade to a new version. I have seen a couple code DOM's that attempt to convert from Delphi to C#, but that doesn't address the library issue.

我不知道有任何用于进行这种转换的自动化工具。我个人建议你坚持使用 Delphi,也许只是升级到新版本。我见过一些尝试从 Delphi 转换为 C# 的代码 DOM,但这并没有解决库问题。

CodeGear (formally Borland) has a tool for going from C# to Delphithat works OK. I would assume the tools that go the other direction will work the same (requiring a lot of editing). Here is a Swedish tool that works on the same CodeDOM principle to go from Delphi to C#(and a number of other languages). There are others, I just can't find them right now.

CodeGear(以前称为 Borland)有一个从 C# 到 Delphi的工具,运行正常。我会假设走向另一个方向的工具将工作相同(需要大量编辑)。这是一个瑞典工具,它以相同的 CodeDOM 原则工作,从Delphi 到 C#(以及许多其他语言)。还有其他的,我现在找不到。

Another option would be to upgrade to a more resent version of Delphi for .NET and port your code to .NET that way. Once you get it working in Delphi for .NET (which will be pretty easy, except for the embedded DB, unless they have a .NET version) you can use .NET Reflectorand File Disassemblerreverse the IL to C#. You will still be using the VCL, but you can use C# instead of Object pascal.

另一种选择是升级到更受欢迎的 Delphi for .NET 版本,并以这种方式将您的代码移植到 .NET。一旦你让它在 Delphi for .NET 中工作(这将很容易,除了嵌入式数据库,除非他们有一个 .NET 版本)你可以使用.NET ReflectorFile Disassembler将 IL 反向到 C#。您仍将使用 VCL,但您可以使用 C# 代替 Object pascal。

Another similar solution would be to port it to Oxygene by RemObjects. I believe they have a Delphi Win32 migration path to WinForms. Then use .NET Reflectorand File Disassemblerreverse the IL to C#.

另一个类似的解决方案是通过 RemObjects将其移植到Oxygene。我相信他们有一个到 WinForms 的 Delphi Win32 迁移路径。然后使用.NET ReflectorFile Disassembler将 IL 反转为 C#。

In short, no easy answers. Language migration is easier then library migration. A lot of it depends on what 3rd party components you used (beyond AbsoluteDatabase) and if you made any Windows API calls directly in your application.

简而言之,没有简单的答案。语言迁移比库迁移更容易。在很大程度上取决于您使用了哪些 3rd 方组件(AbsoluteDatabase 之外)以及您是否直接在应用程序中进行了任何 Windows API 调用。

Another completely different option would be too look for an off shore team to maintain the application. They can probably do so cheaply. You could find someone domestically, but it would cost you more no doubt (although with the sagging dollar and poor job market you never know . . . )

另一个完全不同的选择是寻找离岸团队来维护应用程序。他们可能可以便宜地做到这一点。你可以在国内找人,但无疑会花费更多(尽管美元疲软和就业市场不景气,你永远不知道......)

Good luck!

祝你好运!

回答by dcraggs

Many of my users are moving to Vista which may run the app in compatibility mode or may have GPF problems depending on how their PC is configured by their IT department, so I have to do some maintenance on the application. I'm wondering if I should jump to a more familiar stack.

我的许多用户正在迁移到 Vista,这可能会在兼容模式下运行应用程序,或者可能存在 GPF 问题,具体取决于 IT 部门如何配置他们的 PC,因此我必须对应用程序进行一些维护。我想知道是否应该跳到更熟悉的堆栈。

Unless you are doing something non standard, D7 applications should run fine in Vista.

除非你在做一些非标准的事情,否则 D7 应用程序应该在 Vista 中运行良好。

As for conversion to C#, I would think that most conversion tools would be a waste of time. A better approach may be to rewrite the application from scratch.

至于转换到C#,我认为大多数转换工具都是浪费时间。更好的方法可能是从头开始重写应用程序。

回答by Anthony

There is no easy answer, but bear in mind that the Delphi.net variant of the language targets the .net runtime, and that different languages on .net can interoperate closely.

没有简单的答案,但请记住,该语言的 Delphi.net 变体针对 .net 运行时,并且 .net 上的不同语言可以密切互操作。

You could try getting it to compile in Delphi.Net, factoring into different assemblies and then converting the assemblies by hand one by one. Reflector could help be reverse-engineering compiled code into a skeleton of C# code - equivalent but without comments, internal variable names etc.

您可以尝试让它在 Delphi.Net 中编译,分解为不同的程序集,然后手动逐个转换程序集。Reflector 可以帮助将编译后的代码逆向工程化为 C# 代码的骨架 - 等效但没有注释、内部变量名称等。

On the other hand, Delphi.net may be good enough (TM) for this project.

另一方面,对于这个项目,Delphi.net 可能已经足够好 (TM)。

But unless you have a good test suite (I'm guessing probably not, given the state of the art in Delphi 7) you're going to introduce bugs.

但是除非你有一个好的测试套件(我猜可能没有,考虑到 Delphi 7 的最新技术)你会引入错误。

回答by Stephan Eggermont

There has been a scientific report of a successfull transformation of a 1.5 million line Delphi Project to C# by John Brant. He wrote a Delphi parser, a C# generator and lots of transformation rules on the AST. Gradually extending the set of rules, doing a daily build, lots of unit tests, and some rewriting of difficult Delphi parts allowed him with a team of 4, among which some of the original developers, with deep Delphi & C# knowledge, to migrate the software in 18 months. John Brant being the original developer of the refactoring browser and the SmaCC compiler construction kit, you are unlikely to be able to go that fast

约翰·布兰特 (John Brant) 发表了一份科学报告,称将 150 万行的 Delphi 项目成功转换为 C#。他在 AST 上编写了一个 Delphi 解析器、一个 C# 生成器和许多转换规则。逐渐扩展规则集,每天构建,大量单元测试,并重写一些难的 Delphi 部分,这让他拥有一个 4 人的团队,其中一些原始开发人员具有深厚的 Delphi 和 C# 知识,可以迁移18 个月内的软件。John Brant 是重构浏览器和 SmaCC 编译器构建工具包的原始开发者,你不可能走得那么快