简体   繁体   English

我可以将C ++项目转换为Delphi吗?

[英]Can I convert a C++ project to Delphi?

Is there any way to take an old Borland C++ (v6) project and convert it to Delphi (v7, or maybe XE if that helps, but preferably D7)? 有什么办法可以将旧的Borland C ++(v6)项目转换为Delphi(v7,或者如果有帮助的话可以转换为XE,但最好是D7)?

I seem to recall that BCB could compile Pascal, but not the other way around. 我似乎记得BCB可以编译Pascal,但不能反编译。 In any case, I want to hand the project off to someone who knows no C++ but does know Delphi in order to extend it. 无论如何,我都想将项目交给不懂C ++但不懂Delphi的人来进行扩展。

I do not want to keep any old C++ code, just convert everything to Delphi - manually if I must. 我不想保留任何旧的C ++代码,只需将所有内容都转换为Delphi-如果需要,可以手动进行。

Hope you can save me some time ... 希望您能节省一些时间...

Auto-convert? 自动转换? NO. 没有。 If you're fearing having to do it all yourself, but are willing to do that anyways, then yes, I can confirm for you that there are no silver bullets and you'll have to do it all manually. 如果您担心必须自己完成所有操作,但还是愿意这样做,那么可以,我可以为您确认没有灵丹妙药,您必须手动完成所有操作。

At this point, if you were willing to keep some C++ code around, I'd recommend you do so: 此时,如果您愿意保留一些C ++代码,建议您这样做:

  1. The UI could be built in C++ with C++Builder, and the model (logic code) could stay C++, and also be built in C++Builder. UI可以使用C ++ Builder在C ++中构建,模型(逻辑代码)可以保留在C ++中,也可以在C ++ Builder中构建。

  2. If you wanted to rewrite the UI in delphi, it would not be too hard to have it load up the C++ parts (which would be compiled into a DLL or BPL library) and call them at runtime. 如果要用delphi重写UI,则不难加载它加载C ++部分(这些部分将被编译成DLL或BPL库)并在运行时调用它们。

Note that loading up and calling C++ code from Delphi apps is not hard, and that C++ Builder and Delphi are basically two flavors of the same thing, since C++ Builder is really just a way to write your app in C++ while using a Delphi/pascal UI framework (the VCL) underneath. 请注意,从Delphi应用程序加载和调用C ++代码并不难,并且C ++ Builder和Delphi基本上是同一件事的两种形式,因为C ++ Builder实际上只是在使用Delphi / pascal时用C ++编写应用程序的一种方式。下方的UI框架(VCL)。

So consider either C++Builder (part of RAD Studio) or a Delphi+C++ hybrid, as a complete rewrite of a non-trivial app would take a really long time. 因此,请考虑使用C ++ Builder(RAD Studio的一部分)或Delphi + C ++混合程序,因为要完全重写一个平凡的应用程序将花费很长时间。 But yes, you can rewrite anything into anything else, given enough time. 但是可以,只要有足够的时间,您就可以将任何内容重写为其他内容。 But do you really want to? 但是你真的想要吗?

If your eventual goal is 100% pure Delphi but you wanted to get a partial conversion done first, then finish the conversion later, you could do it in stages if you wanted to; 如果您最终的目标是100%纯的Delphi,但您想先完成部分转换,然后再完成转换,则可以分阶段进行; Link in some C++ parts, load them from DLLs, or even statically link the .obj files into your delphi app. 链接某些C ++部分,从DLL加载它们,甚至将.obj文件静态链接到您的delphi应用程序中。

It seems you are dead set against C++. 看来您对C ++固执己见。 I am a long time C++ hater. 我很讨厌C ++。 If that's your deal, I understand. 如果那是您的交易,我了解。

But let's not be hasty here; 但是,让我们不要草率。 It might not be terribly hard to convert an old Borland C++ OWL library codebase to a modern Visual C++ Codebase using MFC/ATL, either, although IMHO, MFC/ATL are crap. 尽管IMHO,MFC / ATL都是废话,将旧的Borland C ++ OWL库代码库转换为使用MFC / ATL的现代Visual C ++代码库也不是很难。 Consider also, if you should port to QT/C++ or wxWidgets/C++ (you could go cross-platform and get a version that runs on the Mac, and on Linux that way!). 还考虑一下,是否应该移植到QT / C ++或wxWidgets / C ++(您可以跨平台并获得在Mac和Linux上运行的版本!)。 There are so many options for UI, while staying on C++, and that would be certainly easier than manually rewriting the whole thing in a completely different language (Pascal or Python, or C# or Java, really, all the same amount of effort: About as long as it took to write it all in the first place!). 在使用C ++的同时,UI的选择太多了,这肯定比用完全不同的语言(Pascal或Python或C#或Java)手动重写整个事情要容易得多,实际上,所有这些工作量都是相同的:只要将其全部写在第一位!)。 I love pascal, and I prefer it to C++ about 100 times. 我喜欢pascal,相对于C ++,我更喜欢它约100倍。 If anything, I'm biased too much in Delphi's favor. 如果有的话,我对Delphi的支持过于偏颇。 But complete rewrites are almost never practical, and AUTO-CONVERSIONS are also a pipe dream. 但是完全重写几乎是不切实际的,并且AUTO-CONVERSIONS也是梦dream以求的事情。 Modern C++ is actually a pretty nice language. 现代C ++实际上是一种非常不错的语言。 Why rewrite your codebase? 为什么要重写您的代码库?

We recently found ourselves in the same situation : lots of legacy C++ Builder applications, it would take years to convert it all by hand. 我们最近发现自己处在相同的境地:许多旧的C ++ Builder应用程序,要手工转换它们都将花费数年。

So I wrote a little perl script that helps a lot with the conversion. 因此,我写了一些perl脚本,对转换有很大帮助。 It's not 100%, that would be impossible, but it does most of the conversion for you. 不是100%,那是不可能的,但是它可以为您完成大部分转换。 It's free to download and use any way you want. 它是免费下载和使用任何您想要的方式。 Have a look here : http://copycat.fr/wordpress/porting-old-cbuilder-software-to-new-versions/ 在这里看看: http : //copycat.fr/wordpress/porting-old-cbuilder-software-to-new-versions/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM