随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253


自动增长字段:
//建立方法一:
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;

posted on 2010-02-09 16:00  万一  阅读(...)  评论(...编辑  收藏