Delphi XE7 新语法 继承 抽象 纯虚

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Simple_Types_(Delphi)#Enumerated_Types

Delphi Compiler Changes for XE7

String-Like Operations Supported on Dynamic Arrays

  • Dynamic arrays can be manipulated similarly to strings. For example:
var
  A: array of integer;
  B: TBytes = [1,2,3,4]; //Initialization can be done from declaration
begin
  ...
  A:=[1,2,3]; // assignation using constant array
  A:=A+[4,5]; // addition - A will become [1,2,3,4,5]
  ...
end;
sarr:TArray<string>;
还不支持减法这个语法2017.4.6 Berlin
A:= A-[2];
  • String-like support routines added:

I. The Insert function inserts a dynamic array at the beginning at the position index. It returns the modified array.

var
  A: array of integer;
begin
  ...
  A:=[1,2,3,4];
  Insert(5,A,2); // A will become [1,2,5,3,4]
  ...
end;

II. The Delete function eliminates elements from a dynamic array and returns the modifed array:

var
  A: array of integer;
begin
  ...
  A:=[1,2,3,4];
  Delete(A,1,2); //A will become [1,4]
  ...
end;

III. The Concat function can be used to put together two different dynamic arrays:

  A := Concat([1,2,3],[4,5,6]); //A will become [1,2,3,4,5,6]
定义类成员常亮 定义时直接初始化
TDBXDataTypes = class(TDBXSubDataTypes)
const
///<summary></summary>
UnknownType = 0;
///<summary>8 bit Ansi String</summary>
AnsiStringType = 1;
///<summary>32 bit Date</summary>
DateType = 2;
///<summary>Blob with a subtype</summary>
BlobType = 3;
end;
类的静态方法
 class function
  TGUID = record
    D1: Cardinal;
    D2: Word;
    D3: Word;
    D4: array[0..7] of Byte;
    class operator Equal(const Left, Right: TGUID): Boolean;
    class operator NotEqual(const Left, Right: TGUID): Boolean;
    class function Empty: TGUID; static;
    class function Create(const Data; BigEndian: Boolean = False): TGUID; overload; static;
    class function Create(const Data: array of Byte; AStartIndex: Cardinal; BigEndian: Boolean = False): TGUID; overload; static;
  end;

对应的c++builder里就是__classmethod

__classmethod System::UnicodeString __fastcall Fun();

TStringHelper = record helper for string

public

    const Empty = '';
   private type
TSplitKind = (StringSeparatorNoQuoted, StringSeparatorQuoted, CharSeparatorNoQuoted, CharSeparatorQuoted);

字符串数组

for in 类似foreach用法

http://www.cnblogs.com/huangjacky/archive/2009/12/09/1620612.html

arrStr: array of string = ['aaa', 'bbb', 'ccc'];

for i := 0 to Length(arrStr) - 1 do

arrStr[i];

或者

for astr in arrStr do

ListBox1.Items.Add(astr);

抽象方法

abstract

纯虚方法

function GetFlags: TGestureEngineFlags; virtual; abstract;

抽象方法也叫纯虚方法
学习System.Classes.pas的TStrings类定义
http://www.cnblogs.com/del/archive/2008/01/17/1042187.html
http://www.cnblogs.com/findumars/p/4748713.html

abstract 抽象方法是那些在类中声明但未实现的虚拟方法或动态方法。

抽象方法的实现推延到后裔类中。

声明抽象方法必需在指示字virtual或dynamic之后使用abstract。

所谓抽象方法,首先必须是虚拟的或动态的,其次在它所在类中只能声明而
不能定义,只能在派生类中定义它(重载)。因此定义一个抽象方法,只是
定义它的接口,而不定义底层的操作。
只有声明,没有实现。
提现了面向对象的特性。

override 重载,实现多态。实现或覆盖virtual, dynamic, abstract的声明

overload 再定义一个名称相同但参数不同的函数. (调用时自动根据参数选择)。

有抽象方法的类就是抽象类。

http://blog.csdn.net/xinzheng_wang/article/details/6058643

这个语法比较好,面向对象编程,某些场合代替了枚举,有几种选项。

TTableJSon = class
const
  UnknownType = 0;
///<summary>8 bit Ansi String</summary>
AnsiStringType = 1; private const cstFieldType = 'FieldType'; const cstFieldName = 'FieldName'; const cstFieldSize = 'FieldSize'; const cstJsonType = 'JsonType'; const cstRequired = 'Required'; const cstFieldIndex = 'FieldIndex'; const cstCols= 'Cols'; const cstData= 'Data'; procedure test(); end;

c++builder不行

class PASCALIMPLEMENTATION TTableJSon : public System::TObject
{
    typedef System::TObject inherited;

private:
    #define TTableJSon_cstFieldType L"FieldType"
    #define TTableJSon_cstFieldName L"FieldName"
    #define TTableJSon_cstFieldSize L"FieldSize"
    #define TTableJSon_cstJsonType L"JsonType"
    #define TTableJSon_cstRequired L"Required"
    #define TTableJSon_cstFieldIndex L"FieldIndex"
    #define TTableJSon_cstCols L"Cols"
    #define TTableJSon_cstData L"Data"
    void __fastcall test(void);
public:
    /* TObject.Create */ inline __fastcall TTableJSon(void) : System::TObject() { }
    /* TObject.Destroy */ inline __fastcall virtual ~TTableJSon(void) { }

};

用#define转换,但是不能通过对象的实例类访问

TTableJSon *js;

js->cstFieldType; 访问不到,delphi是可以了。

旧语法

函数名相同参数不同的重载

overload;

子类继承父类,重写父类的方法

override;

jgdm: array [0 .. 20] of AnsiChar;

PByte

函数

fun1(para: byte; result: PByte):

调用1

ucbuf: array [0 .. 3] of BYTE;

fun1(para,@ucbuf);

或者

pb: TBytes;

SetLength(pb, 3);

fun1(para,@pb);

byte数组转为integer

it := Integer(ucbuf);

int转为16进制字符

strtemp := Format('0x%02X ', [it]);

c#函数的byte[]参数

getCardInfo( byte[] Data);

delphi为

array of byte;

泛型数组

lParams: TArray<integer>;

lParams[I]

SetLength(lParams, Length(paramInfos));

代替了传统的

array of integer

枚举类型

   type days=(sun,mon,tue,wed,thu,fri,sat);

构造函数

constructor

property WorkareaRect: TRect read GetWorkareaRect;

property WaitTime default 255;

property Scaled: Boolean read GetScaled write SetScaled stored IsForm default True;

SLineBreak是换行符

System.pas

Result := ''

+ 'var' + SLineBreak

字符串下标从0开始

Accesses individual characters in this zero-based string. The Chars property is read-only.

MyString: String;

for I:= 0 to MyString.Length - 1 do

Write(MyString.Chars[I]);

判断dataset是否编辑状态dsEditModes

dsEditModes = [dsEdit, dsInsert, dsSetKey];

Tokyo 10.2.2 Firemonkey下的模态窗口解决方案。

FMX.DialogService

TDialogService.MessageDialog();

TDialogService.InputQuery();

TDialogService.ShowMessage('hello');

procedure TForm2.btnShowMessageClick(Sender: TObject);
begin
  TDialogService.ShowMessage('您点选了OK按钮', ShowMessageCloseMethod);
end;

procedure TForm2.ShowMessageCloseMethod(const AResult: TModalResult);
var
  alvi : TListViewItem;
begin
  alvi := ListView1.Items.Add;
  alvi.Text := DateTimeToStr(Now);
  alvi.Detail := '关闭了ShowMessage对话盒!';
end;

string 字符串下标

一直以来是从1开始

astr.Chars[0]; FMX下提供了从0开始的字符

delphi的TStringHelper提供了该方法。但是c++builder没有。