zoukankan      html  css  js  c++  java
  • 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; 


  • 相关阅读:
    iOS 应用开发入门指南
    修改Visual Studio2010的主题颜色
    C# 获取操作系统相关信息
    WPF Menu控件自定义Style
    Feedback or feedforward?
    Coprimeness
    Admissible, Stabilizability, and Bicoprime Factorization
    Directions of zeros and poles for transfer matrices
    Limit point, Accumulation point, and Condensation point of a set
    Linear System Theory: zero-input response of LTI system
  • 原文地址:https://www.cnblogs.com/jupt/p/3922937.html
Copyright © 2011-2022 走看看