Delphi XE新语法/新功能

编码/解码组件:Added System.NetEncoding unit in RTL.  This unit provides a new TNetEncoding class to unify all internet encoding/decoding:

TNetEncoding.Base64.EncodeString(S);
TNetEncoding.Base64.DecodeString(S);
TNetEncoding.URL.EncodeString(S);
TNetEncoding.URL.DecodeString(S);
TNetEncoding.HTML.EncodeString(S);
TNetEncoding.HTML.DecodeString(S);



动态数组新语法,可以不用Setlength,赋值时候有点类似动态语言。

String-like operations on Dynamic Arrays
o   B := [1, 2, 3, 4];
o   B := B + [5, 6, 7];
o   Insert([6, 7, 8], B, 5); // inserts array [6, 7, 8], into B at index 5
o   Delete(B, 1, 3); // deletes 3 elements starting at index 1
o   Concat([1,2,3,4],[5,6,7])
o   var B: TBytes = [1, 2, 3, 4];
·         Improved initialization for Dynamic Arrays
o   B := [1, 2, 3, 4];
o   B := B + [5, 6, 7];


type
  TBytes = array of Byte;
  TBytesArray = array of TBytes;
  TStrDA = array of string;
 
resourcestring
  Sabc = 'abc';
  Sdef = 'def';
 
var
  B: TBytes = [1, 2, 3, 4];
  C: TBytesArray = [[1, 2, 3], [4,5,6]];
  D: TStrDA = ['ABC', 'DEF'];
  E: TStrDA = [ Sabc, Sdef ];

函数的返回,可以直接用exit(retuanvalue)来替代result:=retuanvalue;exit了.


匿名方法引用(reference to)
以前我们创建一个方法引用的时候会很麻烦,尤其是在类中,需要跳出去在别的地方写一段函数,然后再回来继续写。新的语法reference to避免了这种情况的发生,尤其是许多时候其实我们的方法实际上只有一两句的时候,它可以大大加快开发的速度,就像前面的Exit语法加强一样贴心。不过 遗憾的是,这个类lamda方法的语法糖还不够甜。
type  
   TFoo = reference to function(num: Integer): Integer; // reference to Method
var  
   func: TFoo;  
   n: Integer;  
begin  
   func := function(a: Integer): Integer // *NOTE*: Do NOT Write ‘;’
   begin  
     Result := a * a;  
   end;  
   n := func(10);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值