Embarcadero is about to release a new Delphi compiler for the Linux platform. Here are some of the key technical elements of this compiler, and the few differences compared to Delphi compilers for other platforms.


Embarcadero is about to release a new Delphi compiler for the Linux platform. Here are some of the key technical elements of this compiler, and the few differences compared to Delphi compilers for other platforms.

Linux Intel 64-bit

Before we get to language specific features, let me clarify once more the target platform, as Delphi for Linux is a bit vague. The compiler produces Intel 64-bit executables for Linux. This is a key difference, for example, compared to the old Kylix project compiler, that was 32-bit. The new compiler does not include Linux ARM platforms, which we are considering for the future.

Another related element is that the compiler is based on the LLVM compilers architecture, like all the most recent new Delphi compilers (iOS 32 bit, Android 32 bit, and iOS 64-bit). The advantage is that it will provide some significant optimization on the generated code. The disadvantage is that compiling and linking an application takes considerable more time than when using the Windows compilers.

In the rare case you need platform specific code and when calling platform APIs, you can use the {IFDEF LINUX64}.

Object Pascal Language Compatibility

Getting to the language specifics, the level of language compatibility is going to be very high. Almost all of the classic Pascal-based languages features, OOP features, RAD support capabilities, modern Pascal features (generics, anonymous methods, reflection, attributes) are going to work the same. Some beta testers have been able to port significantly complex libraries in a fairly smooth way.

What you might find a little more trouble in is porting some "older" code, like code that is not Unicode enabled or relies heavily on Windows-ism. Below are some of the specific differences. The only area that is not meant to be fully compatible is memory management, given the new compiler is based on Automatic Reference Counting, as explained later.

Core Data Types and LongWord Blues

I'm not going to list all of the core data types that remain the same, as the list is very long, but let's look at what's specific to this compiler. Being a 64-bit compiler, all pointers are going to be 64-bit, while Integer stay 32-bit -- this is the behavior of all other Delphi 64-bit compilers (and most other programming languages, BTW).

The only caveat is for the LongWord type. This is a data type often used when making operating system calls, so the decision that was taken some time ago was to keep it matching the underlying OS. So, for example, on iOS the same API declaration with LongWord compiles to a 32-bit or 64-bit data type depending on the compiler you are using. On Windows, however, Microsoft made a non-standard decision to keep LongWord the same size of an Integer. This implies the Windows 64-bit platforms works differently from the Linux 64-bit platform in regard of this data type. For reference, among other sources, see the long type in C language on different platforms at https://en.wikipedia.org/wiki/Integer_(computer_science)#Long_integer and the first answer at http://stackoverflow.com/questions/384502/what-is-the-bit-size-of-long-on-64-bit-windows.

You might have to revisit you code using LongWord and decide to keep that data type or use a different one (Integer, UInt32, NativeUInt...) depending on your goal. We have done and are still doing a significant revision of the RTL to make sure we are not misusing this type. In same cases, however, we are going to keep code that behaves differently depending on the platform, particularly when changing core RTL classes would cause a lot of legitimate Windows code working for 20 years not to compile any more.

Strings and Encodings

Since Delphi 2009 the Object Pascal language string type has defaulted to UTF-16 Unicode and 2-byte Char data type. Needless to say the Linux compiler follows the same path. Since 10.1 Berlin, all compilers (including the mobile ones) received full support for the UTF8String type and also (for direct low-level processing) the RawByteString type. The Linux compiler includes these data types, and in fact the UTF8String was added to mobile mostly because we anticipated it as a key requirement for Linux. A significant part of the HTTP-based traffic uses UTF-8 and supporting this representation as a native type -- beside supporting encoding to it -- was considered a requirement for the Linux project.

It is true, however, that some other string types like AnsiString are not supported. This is mostly a "Windows-centric" data type. If you are still using strings and PChar for managing generic data structures, it is really time to move to TBytes and PByte instead -- or enable pointer math for all data structures. Also the support for the old Pascal ShortString type is limited. Declaring a string [20] variable on Linux will fail. The other string type that is not supported is WideString. This is the old pre-Unicode non-reference counted UTF-16 type used for Windows COM platform integration. In fact, any COM-specific type and feature is missing on Linux, like on all other non-Windows Delphi platforms.

Notice that the TEncoding support is available, so you can read and write text files in any format you want. What you are not directly able to do is process an AnsiString in memory with the standard language support. But you can have an array of bytes (TBytes) representing text in any format in memory, and read and write it on disk, or receive and send via a socket connection, and you can use the TEncoding support for conversions.

Linux Defaults to 1-Based String Access

What about string access via the [] operator? As you might know, there is a compiler default you can change per-project, per-unit, or even per-code fragment that determines if the compiler treats the string access operator with a 1-based Pascal-classic notation or the 0-based notation most programming languages use. While mobile compilers default to 0-based, for Linux we decided to stick with the traditional Windows model, on the ground developers are mostly likely to migrate existing Windows server side code to Linux. The recommendation is to try to use clean, agnostic code, but if you prefer forcing a given string access model for all of your Delphi code, just use the $ZEROBASEDSTRINGS directive in your projects. Just as a reminder all RTL string functions and the newer string helper methods stays the same regardless of the platform and this setting. The first group uses a 1-based logic, the second a 0-based logic. Your pick.

Here Comes ARC

The other notable change from the Windows compiler is that on the Linux platform (as in any new platform) we have decided to use the Automatic Reference Counting (ARC) model for memory management. This is the model Delphi uses for all mobile compilers plus the iOS simulator one. The long term plan is to shift the entire Delphi ecosystem in that direction -- probably keeping the VCL world on the traditional memory model. This is the reason not-picking ARC for Linux would have been very confusing, as given you need testing when adopting a new platform this is the least disruptive moment for such a transition.

Feedback from beta testers has been fairly positive on this, and migration of existing code and libraries has not bumped into big hiccups. Now I don't have room in this blog post to revisit the best practices for ARC migration, but I'll try to have some more extensive material on this in the future.

Shameless plug: My Object Pascal Handbook (and particularly the Berlin revised edition) has some good material on this.

More Information? Delphi Linux BootCamp is Coming!

For more information, sign up to the boot camp (which is actually a one hour webinar) scheduled for March 1st in 3 times zones. For more information and to sign up see https://community.embarcadero.com/blogs/entry/delphi-linux-boot-camp

http://blog.marcocantu.com/blog/2017-february-delphi-linux-compiler.html

Delphi For Linux Compiler的更多相关文章

  1. Delphi CompilerVersion Constant / Compiler Conditional Defines

    http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...

  2. 对于delphi for linux心存梦想的同学,彻底醒醒吧

    Borland 曾经多次做市场调查,很多人呼吁推出delphi for linux.可是直到kylix发展到第三版,borland才明白:一个内置C编译器环境并与之关系紧密的免费OS,没有人愿意花钱去 ...

  3. DELPHI开发LINUX桌面程序

    DELPHI开发LINUX桌面程序 DELPHI官方目前为止尚不能开发LINUX桌面程序. 但三方控件FmxLinux(商业控件)是可以的.网上有破解版本.

  4. DELPHI开发LINUX插件架构的程序

    DELPHI开发LINUX插件架构的程序 DELPHI可以开发LINUX配置型插件架构的程序,并且这一套插件架构,同样适用于MSWINDOWS和MAC. 配置插件: 根据配置,动态加载插件:

  5. DELPHI开发LINUX包

    DELPHI开发LINUX包 我们知道,有了包的存在,开发插件架构的程序,才成为可能 . DELPHI在WINDOWS里面的包的扩展名是.bpl. 在LINUX里面的包的扩展名是.so. 怎样在LIN ...

  6. DELPHI开发LINUX的动态库

    DELPHI开发LINUX的动态库 WINDOWS的动态库是.dll,这个大家都知道. LINUX也有动态库,扩展名是.so,现在DELPHI也能开发LINUX的动态库哦. DELPHI对LINUX的 ...

  7. delphi 开发者 linux 实务(转)

    Linux Essentials for Delphi Developers   There is currently no way using Delphi to target Linux. Lon ...

  8. 在RedHat 和 Ubuntu 中配置 Delphi 的Linux开发环境(转)

    原文地址:http://chapmanworld.com/2016/12/29/configure-delphi-and-redhat-or-ubuntu-for-linux-development/ ...

  9. 咏南 DELPHI DATASNAP LINUX中间件

    咏南 DATASNAP LINUX中间件   咏南 DATASNAP LINUX中间件,一套源码,同时支持WINDOWS和LINUX操作系统. 基于DELPHI 10.2 TOKYO开发 使用FIRE ...

随机推荐

  1. mysql半同步复制实现

    mysql半同步复制和异步复制的区别如上述架构图所看到的:在mysql异步复制的情况下.Mysql Master Server将自己的Binary Log通过复制线程传输出去以后,Mysql Mast ...

  2. Android小游戏:功夫蛇 团队开发经验总结

    前言 曾经没有代码管理的习惯,不用回版本控制工具.这种陋习虽然让原来千穿百孔的代码远离了实现,但这种逃避未必就是一件好事吧;). 于是从博客中挖出了原来的文章,并千辛万苦找到了最早的代码贴出来. 这篇 ...

  3. Msg DisPatch

    一天写了个Carlife 协议数据分流器 #include <stdio.h> #include <string.h> typedef unsigned char uint8_ ...

  4. wpf设置设计时的ViewModel

    原文:wpf设置设计时的ViewModel wpf mvvm开发中,有些情况下,你的view不一定设置DataContext,但是你又想在设计阶段,能够自动提示你的view绑定的viewmodel的内 ...

  5. Codeforces 449 B. Jzzhu and Cities

    堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...

  6. Linux socket编程示例(最简单的TCP和UDP两个例子)

    一.socket编程 网络功能是Uinux/Linux的一个重要特点,有着悠久的历史,因此有一个非常固定的编程套路. 基于TCP的网络编程: 基于连接, 在交互过程中, 服务器和客户端要保持连接, 不 ...

  7. VS编译环境中TBB配置和C++中lambda表达式

    TBB(Thread Building Blocks),线程构建模块,是由Intel公司开发的并行编程开发工具,提供了对Windows,Linux和OSX平台的支持. TBB for Windows ...

  8. HDU 3153 Pencils from the 19th Century(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3153 Problem Description Before "automaton" ...

  9. Opencv决策树分类器应用

    机器学习在数据挖掘.计算机视觉.搜索引擎.医学诊断.证券市场分析.语言与手写识别等领域有着十分广泛的应用,特别是在数据分析挥着越来越重要的作用.在机器学习中,决策树是最基础且应用最广泛的归纳推理算法之 ...

  10. Domain adaptation:连接机器学习(Machine Learning)与迁移学习(Transfer Learning)

    domain adaptation(域适配)是一个连接机器学习(machine learning)与迁移学习(transfer learning)的新领域.这一问题的提出在于从原始问题(对应一个 so ...