自动增长字段:
//建立方法一: begin with ClientDataSet1 do begin FieldDefs.Add('ID', ftAutoInc); FieldDefs.Add('Name', ftString, 11); CreateDataSet; end; end; //建立方法二: begin with TAutoIncField.Create(Self) do begin FieldName := 'ID'; // AutoGenerateValue := arAutoInc; { 不起作用 } DataSet := ClientDataSet1; end; with TStringField.Create(Self) do begin FieldName := 'Name'; Size := 11; DataSet := ClientDataSet1; end; ClientDataSet1.CreateDataSet; end;
字段默认值:
begin with TStringField.Create(Self) do begin FieldName := 'Name'; Size := 11; DataSet := ClientDataSet1; end; with TIntegerField.Create(Self) do begin FieldName := 'Age'; DefaultExpression := '18'; DataSet := ClientDataSet1; end; ClientDataSet1.CreateDataSet; end;