Lazarus中objfpc編譯模式與delphi編譯模式的不同
(2011-03-28 23:33:22)
今天碰到了Lazarus編譯模式的問題,以前一直認為Lazarus和delphi語法之類的都是一樣的, 今天在事實面前證明,不一樣!
編譯模式的聲明是在文件開頭,unit 下面
{$mode delphi
} 或者 {$mode objfpc
}
Lazarus官網說明:
This mode is selected by the $MODE DELPHI switch. It tries to emulate, as
closely as possible, the behavior of Delphi 4 or higher. On the
command line, this mode is selected by the -Mdelpih switch.//http://www./blog
- You cannot use the address
operator to assign procedural variables.
- A forward declaration does
not have to be repeated exactly the same by the implementation of a
function/procedure. In particular, you can omit the parameters when
implementing the function or procedure.
- Ansistrings are default,
this means that $MODE DELPHI implies
an implicit {$H
ON}.
- Overloading of functions
is not allowed. //http://www./blog
- Nested comments are not
allowed.
- The Objpas unit is loaded
right after the system unit. One of
the consequences of this is that the type Integer is redefined as Longint.
- Parameters in class
methods can have the same names as class properties (although it is
bad programming practice).//http://www./blog
This mode is selected by the $MODE OBJFPC switch. On the command line, this
mode is selected by the -Mobjfpc
switch.
- You must use the address
operator to assign procedural variables.
- A forward declaration must
be repeated exactly the same by the implementation of a
function/procedure. In particular, you cannot omit the parameters
when implementing the function or procedure, and the calling
convention must be repeated as well.
- Overloading of functions
is allowed.
- Nested comments are
allowed.
- The Objpas unit is loaded
right after the system unit. One of
the consequences of this is that the type Integer is redefined as Longint.
- You can use the cvar
type.
- PChars are converted to
strings automatically.
- Parameters in class
methods cannot have the same names as class properties.
- Strings are shortstrings
by default. You can use the -Sh
command line switch or the {$H+} switch to change this.
Minun幫忙的解釋:
//http://www./blog
D.3 Delphi mode
1、你不能在函數指針或者運算符上使用地址符號
2、事先的申明可以省略參數
3、AnsiString是默認的,
4、同名函數是不允許的
5、備注嵌套是不允許的
6、objpas加載在system之后,明顯的區別在于integer是longint
7、類方法的參數可以與類屬性同名
D.4 OBJFPC mode
1、你必須在函數指針或者運算符上加上地址符號
2、事先的生命必須完全和后面的實現相符合,相反,你可以在實現中省略參數
3、同名函數是允許的//http://www./blog
4、備注嵌套是允許的//http://www./blog
5、objpas加載在system之后,(和delphi一樣)
6、你可以使用cvar類型
7、PChars被自動當作strings處理
8、類方法的參數不能與類屬性同名
9、String默認是ShortString,
一個例子:
記錄類型
ta=record
a:integer;
end ;
Pta=^ta;
=====================
第一種寫法:
var
s:Pta;
begin
s:=new(pta);
s.a:=5; end;
第二種寫法:
var
s:Pta;
begin
s:=new(pta);
s^.a:=5; end;
//http://www./blog
第一種第二種寫法在Delphi模式下都能通過,而在objfpc下只能通過第二種。
|