• TClientDataSet中关于TField、TFieldDef动态创立字段的应用


    //使用 TFieldDef 建表:  
    begin 
     with ClientDataSet1.FieldDefs do 
     begin 
      Add('Name' , ftString, 12, True); { True 表示是必填字段 } 
      Add('Age', ftInteger); 
     end; 
     ClientDataSet1.CreateDataSet; 
    end; 
     
    //使用 TField(这里是用其子类)建表: 
    begin 
     with TStringField.Create(Self) do 
     begin 
      FieldName := 'Name'; 
      Size := 12; 
      Required := True; { 必填字段 } 
      DataSet := ClientDataSet1; 
     end; 
     with TIntegerField.Create(Self) do 
     begin 
      FieldName := 'Age'; 
      DataSet := ClientDataSet1; 
     end; 
     ClientDataSet1.CreateDataSet; 
    end; 
     
    //混合使用(这好像就是设计时的情形): 
    var 
     F: TIntegerField; 
    begin 
     with ClientDataSet1.FieldDefs.AddFieldDef do 
     begin 
      Name := 'Name'; 
      DataType := ftString; 
      Size := 12; 
      Required := True; 
      CreateField(ClientDataSet1); 
     end; 
     with ClientDataSet1.FieldDefs.AddFieldDef do 
     begin 
      Name := 'Age'; 
      DataType := ftInteger; 
      { 指定最大值和最小值 } 
      F := CreateField(ClientDataSet1) as TIntegerField; 
      F.MinValue := 0; 
      F.MaxValue := 150; 
     end; 
     ClientDataSet1.CreateDataSet; 
    end; 


  • 相关阅读:
    css布局模型
    HTML元素分类
    《水经注》卷三十五
    《水经注》卷二十八
    沧浪之水
    网页布局基础
    IndexError: tuple index out of range
    树回归-CART
    树回归-CART
    支持向量机SVM
  • 原文地址:https://www.cnblogs.com/jupt/p/3922937.html
Copyright © 2020-2023  润新知