Delphi For Linux Compiler
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的更多相关文章
- Delphi CompilerVersion Constant / Compiler Conditional Defines
http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the in ...
- 对于delphi for linux心存梦想的同学,彻底醒醒吧
Borland 曾经多次做市场调查,很多人呼吁推出delphi for linux.可是直到kylix发展到第三版,borland才明白:一个内置C编译器环境并与之关系紧密的免费OS,没有人愿意花钱去 ...
- DELPHI开发LINUX桌面程序
DELPHI开发LINUX桌面程序 DELPHI官方目前为止尚不能开发LINUX桌面程序. 但三方控件FmxLinux(商业控件)是可以的.网上有破解版本.
- DELPHI开发LINUX插件架构的程序
DELPHI开发LINUX插件架构的程序 DELPHI可以开发LINUX配置型插件架构的程序,并且这一套插件架构,同样适用于MSWINDOWS和MAC. 配置插件: 根据配置,动态加载插件:
- DELPHI开发LINUX包
DELPHI开发LINUX包 我们知道,有了包的存在,开发插件架构的程序,才成为可能 . DELPHI在WINDOWS里面的包的扩展名是.bpl. 在LINUX里面的包的扩展名是.so. 怎样在LIN ...
- DELPHI开发LINUX的动态库
DELPHI开发LINUX的动态库 WINDOWS的动态库是.dll,这个大家都知道. LINUX也有动态库,扩展名是.so,现在DELPHI也能开发LINUX的动态库哦. DELPHI对LINUX的 ...
- delphi 开发者 linux 实务(转)
Linux Essentials for Delphi Developers There is currently no way using Delphi to target Linux. Lon ...
- 在RedHat 和 Ubuntu 中配置 Delphi 的Linux开发环境(转)
原文地址:http://chapmanworld.com/2016/12/29/configure-delphi-and-redhat-or-ubuntu-for-linux-development/ ...
- 咏南 DELPHI DATASNAP LINUX中间件
咏南 DATASNAP LINUX中间件 咏南 DATASNAP LINUX中间件,一套源码,同时支持WINDOWS和LINUX操作系统. 基于DELPHI 10.2 TOKYO开发 使用FIRE ...
随机推荐
- 学习鸟哥的Linux私房菜笔记(11)——系统监视1
一.了解系统状况 uname:显示系统信息 hostname:显示主机名 last:列出最近的用户登录 lastlog:列出每一个用户的最近登录情况 free:显示内存使用状况 还可以使用vmstat ...
- Fiddler快速入门(还有一个功能就是不经过网络,直接模拟一个响应返回给客户端)
Fiddler是一个免费.强大.跨平台的HTTP抓包工具.Wireshark也是一个强大的抓包工具,不过Wireshark是一个通用的抓包工具,主要精力放在各种协议上了,针对HTTP的特定功能较少.所 ...
- Python采用struct处理二进制
有时需要使用python二进制数据,实例,件.socket操作时.这时候.能够使用python的struct模块来完毕.能够用 struct来处理c语言中的结构体. struct模块中最重要的三个函数 ...
- eCognition学习记录
作者:朱金灿 来源:http://blog.csdn.net/clever101 昨天公司从外面请了人讲解eCognition的最新进展及项目二次开发应用情况.我做了大致下面记录: 1. eCogn ...
- 【cocos2dx 加载资源目录】
从互联网下载vsproject代码.编译一切都还好吗,当发现向导的最后一个执行create没有找到图片功能异常.看图片Resource的内容下表,他没有排除的图像的可能性. 那么之后呢?!仅仅能是pr ...
- Tomcat 8(十)HTTP/AJP Connector、Bio/Nio/Apr性能对照
Tomcat 8(七)解读Bootstrap介绍过,Connector初始化/启动的时候,将初始化/启动内部的ProtocolHandler.事实上ProtocolHandler仅仅是个接口 Prot ...
- Linux性能测试 ss命令
ss即socket state,也就是说,是可以查看系统中socket的状态的.我们可以用netstat,但为什么还要用ss这个工具呢,当然ss也是有好处的.当我们打开的socket数量很多时,net ...
- VC除零异常(错误)捕获
// testFinally.cpp : Defines the entry point for the console application. // #include "stdafx.h ...
- 好玩的WPF第三弹:颤抖吧,地球!消失吧,地球!
原文:好玩的WPF第三弹:颤抖吧,地球!消失吧,地球! 版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net ...
- (015)实现一个函数来检查是否平衡树(keep it up)
实现一个函数来检查是否平衡树.这个问题而言. 平衡指的是这棵树随意两个叶子结点到根结点的距离之差不大于1. 这个题我们能够採用暴力搜索,找到叶子节点到根节点的最小值和最大值.然后他们的差假设大于1就不 ...