Migrating a Project to Delphi Prism from Delphi.NET
2011-04-23 15:44
393 查看
As we know, now that the future of Delphi.NET is Delphi Prism (based on the RemObjects Oxygene compiler) we have to migrate our Delphi.NET projects to be compatible with the Prism compiler.
The Easiest way to get started is to look at the free Oxidizer tool provided on the RemObjects Wiki. The tool helps with the conversion of Delphi Win32 projects to Delphi Prism (but I’m uncertain about how it performs on Delphi.NET to Delphi Prism). The Wiki is also an excellent place to get started, particularly the pages on Delphi Win32 vs Delphi Prism which list the major incompatibilities between the two languages.
Whilst converting my Delphi.NET Library for accessing Twitter, I encountered a few basic hints and tips which I felt I should share here:
You need to specify the namespace keyword at the top of your unit file instead of the unit keyword. The first time I tried to compile after doing this Prism still complained about not having a namespace keyword present, this was fixed by closing the solution and re-opening.
Delphi Prism automatically makes classes that are not explicitly marked otherwise as strict private. This meant that I had to go through my library and mark all classes that I wanted to make public. eg. TMyClass = public class(System.Object);
The overload keyword isn’t neccesary as overloading is now implicit. This isn’t a problem at all and isn’t dificult to fix as it simply meant doing a Search and Replace for the overload keyword and removing it.
TObject no long exists and instead needs to be replaced with System.Object which has much the same properties.
I encountered a few problems with the use of for .. in loops. It would seem that Delphi Prism loop variables are local to the loop and therefore should be declared at the beginning of the loop (see the for wiki page for more info). In reality this meant changing: for strItem in list do to [b]for strItem: string in list do and then removing the strItem: string; declaration in the method var section.[/b]
The TObject.Create([...]); constructor still exists however it is now recommended that you switch to the new Object([..]) keyword for new projects. This may come as a shock to traditional Delphi’ers who have been .Create()‘ing since the dawn of Borland but this is the construction method that sems to fit in with the .NET framework better. There is also a compatibility flag in the Project properties which allows the compiler to work some magic to allow .Create to continue to function.
These are not the only changes that you will probably need to make but I found them to be a good starting point. You should definitely consult the Prism Wiki for help in which I was able to find answers very quickly (no wading boots required!).
Lastly: My project could do with a lot of refactoring in order to take advatages of the unique language features of Prism. This will take considerably more time as it means learning the new language features first!
The Easiest way to get started is to look at the free Oxidizer tool provided on the RemObjects Wiki. The tool helps with the conversion of Delphi Win32 projects to Delphi Prism (but I’m uncertain about how it performs on Delphi.NET to Delphi Prism). The Wiki is also an excellent place to get started, particularly the pages on Delphi Win32 vs Delphi Prism which list the major incompatibilities between the two languages.
Whilst converting my Delphi.NET Library for accessing Twitter, I encountered a few basic hints and tips which I felt I should share here:
You need to specify the namespace keyword at the top of your unit file instead of the unit keyword. The first time I tried to compile after doing this Prism still complained about not having a namespace keyword present, this was fixed by closing the solution and re-opening.
Delphi Prism automatically makes classes that are not explicitly marked otherwise as strict private. This meant that I had to go through my library and mark all classes that I wanted to make public. eg. TMyClass = public class(System.Object);
The overload keyword isn’t neccesary as overloading is now implicit. This isn’t a problem at all and isn’t dificult to fix as it simply meant doing a Search and Replace for the overload keyword and removing it.
TObject no long exists and instead needs to be replaced with System.Object which has much the same properties.
I encountered a few problems with the use of for .. in loops. It would seem that Delphi Prism loop variables are local to the loop and therefore should be declared at the beginning of the loop (see the for wiki page for more info). In reality this meant changing: for strItem in list do to [b]for strItem: string in list do and then removing the strItem: string; declaration in the method var section.[/b]
The TObject.Create([...]); constructor still exists however it is now recommended that you switch to the new Object([..]) keyword for new projects. This may come as a shock to traditional Delphi’ers who have been .Create()‘ing since the dawn of Borland but this is the construction method that sems to fit in with the .NET framework better. There is also a compatibility flag in the Project properties which allows the compiler to work some magic to allow .Create to continue to function.
These are not the only changes that you will probably need to make but I found them to be a good starting point. You should definitely consult the Prism Wiki for help in which I was able to find answers very quickly (no wading boots required!).
Lastly: My project could do with a lot of refactoring in order to take advatages of the unique language features of Prism. This will take considerably more time as it means learning the new language features first!
相关文章推荐
- Converting a project from VS.NET 2003 to VS.NET 2002
- Unable to get the project file from the Web Server(in .NET 2005 IDE)
- Visual Studio .Net 2003 Error: "Refreshing the project failed. Unable to retrieve folder information from the server."
- 从LM3S到LM4F TM4C ARM Cortex-M4 : Migrating Software Projects from StellarisWare® to TivaWare™
- Migrating an Existing Website from SQL Membership to ASP.NET Identity
- Migrates from Delphi to C#.NET
- log4j的1.2.15版本,在pom.xml中的顶层project报错错误: Failure to transfer javax.jms:jms:jar:1.1 from https://maven-repository.dev.java.net/nonav/repository......
- How To Create an ASP.NET Application from Multiple Projects for Team Development
- Migrating Delphi Applications to .NET
- Migrating Your Android App from Eclipse to Android Studio
- Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the
- ASP.NET MVC Framework: Passing ViewData from Controllers to Views
- Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy! 转
- ehcache-core版本导致异常 tried to access method net.sf.ehcache.config.CacheConfiguration.<init>()V from cl
- 徐博 From RankNet to LambdaRank to LambdaMART: An Overview
- This version of Visual Studio .NET does not support source controlled projects. Any changes that you make to this project will n
- This event supports the .NET Framework infrastructure and is not intended to be used directly from your code?继承自VScrollbar的自定义winform控件,某些事件不触发的问题(Winform控件开发学习)
- Upgrading from ASP.NET 1.1 to 2.0
- 64 bit OS IIS Setup .net project, 不是有效的 Win32 应用程序。 (Exception from HRESULT: 0x80070 错误解决方案
- How to delete a team project from Team Foundation Service (tfs.visualstudio.com)