free pascal dialect

Free pascal 本身支持多种dialect方言(或者叫mode), 支持 objfpc/delphi/delphiunicode, 还有 tp/iso 等不常用的方言.

在一个项目中,  dialect 是 per unit 设定的.

不同方言支持的语法有些许区别, 主要不同体现在:  string类型具体实现形式不同, 泛型语法不同, 函数指针语法等.

官方文档:

$mode指令: https://www.freepascal.org/docs-html/prog/progap4.html#progse62.html

$H指令: https://www.freepascal.org/docs-html/prog/progsu25.html

$MODESWITCH 指令:  https://www.freepascal.org/docs-html/prog/progsu106.html

各种string的说明:  https://wiki.freepascal.org/FPC_Unicode_support#RTL_todos

需要说明的是, {$mode objfpc}{$H+}  下, string 其实为 AnsiString , Lazarus 项目缺省模式 , 但如果在开启 {$MODESWITCH UNICODESTRINGS} , string 将变为UnicodeString.

下面Free pascal 程序不能运行, 但可以通过报错信息测试, 在不同mode下string类型等价于哪种具体实现类型.

program Project1;
//{$mode objfpc}{$H+}      //string 其实为 AnsiString , Lazarus 项目缺省模式
//{$mode objfpc }          //string 其实为 ShortString
//{$mode DELPHI }          //string 其实为 AnsiString
//{$mode DELPHIUNICODE }   //string 其实为 UnicodeString

//$mode指令: https://www.freepascal.org/docs-html/prog/progap4.html#progse62.html
//$H指令: https://www.freepascal.org/docs-html/prog/progsu25.html
uses SysUtils, classes;
var
  msg:string ;
  AList:TList ;
begin
  AList:=TList.create() ;
  Alist.Add(msg);
end.
           

原文地址:https://www.cnblogs.com/harrychinese/p/free_pascal_dialect.html