简体   繁体   English

如何从C ++ Builder移植?

[英]How to port from C++ Builder?

I have this large program written in C++ Builder, relying heavily on the VCL graphics library. 我有一个用C ++ Builder编写的大型程序,很大程度上依赖于VCL图形库。 For many reasons, I want to abandon this tool. 由于许多原因,我想放弃此工具。 There are a couple of alternative compilers to move to, I'm open for any of them. 有两个可供选择的编译器可供使用,我对其中任何一个都开放。

What I wonder is how one would do the actual porting, step by step? 我想知道的是,如何逐步进行实际的移植? Has anyone done this and could share their experience? 有没有人做到这一点并可以分享他们的经验?

I would imagine that step 1 is to separate the GUI/VCL from the application. 我想第一步是将GUI / VCL与应用程序分开。 The program should have been designed like that anyhow, but sadly it isn't. 该程序本来应该是这样设计的,但遗憾的是事实并非如此。 That alone is a major project, but where do I go after that? 仅此一项是一个重大项目,但是那之后我应该去哪里呢? Should I link up the VCL GUI in .dll files, include them in the new compiler, but maintain them from Builder if needed? 我是否应该在.dll文件中链接VCL GUI,将它们包括在新的编译器中,但是如果需要,可以从Builder对其进行维护?

I agree you should separate the presentation layer from the business logic. 我同意您应该将表示层与业务逻辑分开。

If you're looking for an alternative GUI framework to the VCL, you could consider Qt . 如果您正在寻找VCL的替代GUI框架,则可以考虑Qt It also comes with an IDE that has a UI designer (so is comparable to C++ Builder), but with the advantages of being both cross platform and open source. 它还带有一个具有UI设计器的IDE(因此与C ++ Builder相当),但具有跨平台和开源的优点。

I had the same situation with MFC once. 我曾经在MFC遇到过同样的情况。 my advice is start from scratch and reuse whatever you can from old code, and don't mess presentation with logic this time! 我的建议是从头开始,并重用旧代码中的所有内容,并且这次不要使逻辑混乱! ;) ;)

I would start -- as you say -- by separating the presentation layer from the business logic. 正如您所说的那样,我首先将表示层与业务逻辑分开。 Start by doing this in the familiar C++ Builder environment: remove the business logic from the application and recreate it as one or more separate modules (DLLs, on Windows), and change the presentation layer so that the program still runs but accesses these modules for all business logic operations. 首先在熟悉的C ++ Builder环境中执行此操作:从应用程序中删除业务逻辑,并将其重新创建为一个或多个单独的模块(在Windows上为DLL),并更改表示层,以便程序仍可运行,但可以访问这些模块以用于所有业务逻辑操作。

Then you can rewrite the application without using VCL. 然后,您可以在不使用VCL的情况下重写应用程序。 You might stick with C++ and use another GUI library (Qt is certainly one of the options, wxWidgets is also worth a look) or you might want to change language (depending on your own skills and preferences) for the presentation layer. 您可能会坚持使用C ++并使用另一个GUI库(Qt当然是其中的一种,wxWidgets也很值得一看),或者您可能想更改表示层的语言(取决于您自己的技能和偏好)。

Another attraction to moving the business logic out of the presentation is that it then becomes much more easily testable. 将业务逻辑移出演示文稿的另一个吸引人之处在于,它随后变得更加易于测试。

I'd recommend taking a look at Michael Feathers's book Working Effectively with Legacy Code before you start. 我建议您在开始之前先阅读一下迈克尔·费瑟斯(Michael Feathers)的书《有效地使用旧版代码》 He gives a good (and very test-based) approach to this sort of refactoring. 他为这种重构提供了一种很好的方法(并且非常基于测试)。

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

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