简体   繁体   English

如何使用ClientDataset在运行时中创建必填字段

[英]How create a mandatory field in runtime using a ClientDataset

I'm using this code to create a set of fields in runtime 我正在使用此代码在运行时创建一组字段

  ClientDataSet1.FieldDefs.Add('ID', ftInteger, 0);
  ClientDataSet1.FieldDefs.Add('Serial', ftInteger, 0);
  ClientDataSet1.FieldDefs.Add('Customer', ftString, 40);
  ClientDataSet1.FieldDefs.Add('Address', ftString, 40);
  ClientDataSet1.CreateDataSet;

Now I want to make some fields mandatory, how i can define a field created in runtime as mandatory? 现在,我想使某些字段为必填字段,如何将在运行时创建的字段定义为必填字段?

The add method has a fourth parameter called required add方法具有第四个参数,称为required

procedure Add(const Name: string; DataType: TFieldType; Size: Integer = 0;
  Required: Boolean = False);

set that value to True and your field will be mandatory. 将该值设置为True,则您的字段为必填字段。

example to make mandatory the field ID use this code 强制字段ID使用此代码的示例

ClientDataSet1.FieldDefs.Add('ID', ftInteger, 0, True);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM