• Migrating a Project to Delphi Prism from Delphi.NET


    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 for strItem: string in list do and then removing the strItem: string; declaration in the method var section.
    • 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!

  • 相关阅读:
    微信分享 apicloud方式 中遇到的坎
    css之颜色篇
    css总结
    记一些茅塞顿开的事情
    apicloud
    安装MySQL
    智能家居
    java
    数据库设计好不好,分配很重要。
    WP8.1的shell:SystemTray去哪了?
  • 原文地址:https://www.cnblogs.com/LeoWong/p/2025699.html
Copyright © 2020-2023  润新知