码迷,mamicode.com
首页 > 其他好文 > 详细

内存表 ClientDataSet CreateDataSet

时间:2015-02-04 16:31:09      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

ClientDataSet FieldDefs Add Field CreateDataSet

void __fastcall TForm1::createField()
{
  ClientDataSet1->Close();

  ClientDataSet1->Fields->Clear();
  ClientDataSet1->FieldDefs->Clear();

  ClientDataSet1->Open();
  ClientDataSet1->Close();
  for(int i = 0 ;i < ClientDataSet1->Fields->Count - 1;i++)
   ClientDataSet1->Fields->Fields[0]->Free();//释放所有的静态字段
  for(int i = 0 ;i < ClientDataSet1->FieldDefs->Count - 1;i++)
    ClientDataSet1->FieldDefs->Items[i]->CreateField(ClientDataSet1);

  TBooleanField *NewField; 
  NewField = new TBooleanField(ClientDataSet1);
  NewField->FieldName="SelectMe";
  NewField->DisplayLabel = "选择";
  NewField->FieldKind=fkInternalCalc;
  NewField->DataSet=ClientDataSet1;
  NewField->Index = 0;
  ClientDataSet1->Open();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
        sql = "select  from TABLE1 ";
        this->ADOQuery1->Close();
        this->ADOQuery1->SQL->Clear();
        this->ADOQuery1->SQL->Add(this->sql);
        this->ADOQuery1->Open();
        this->createField();
}

 

  cds1->Close();
  cds1->FieldDefs->Clear();
  cds1->FieldDefs->Add("ID", ftInteger, 0, true);
  cds1->FieldDefs->Add("Name", ftString, 20, false);
  cds1->FieldDefs->Add("DT", ftDateTime, 0, false);
  cds1->CreateDataSet();  
  cds1->AppendRecord(  ARRAYOFCONST((101,"aaa",Now().DateTimeString() )));
  cds1->AppendRecord(  ARRAYOFCONST((102,"bbb",Now().DateTimeString() )));
  cds1->AppendRecord(  ARRAYOFCONST((103,"ccc",Now().DateTimeString() )));
  ClientDataSet1.Close();
  ClientDataSet1.FieldDefs.Clear();
  ClientDataSet1.FieldDefs.Add(ID, ftInteger, 0, true);
  ClientDataSet1.FieldDefs.Add(Name, ftString, 20, false);
  ClientDataSet1.FieldDefs.Add(DT, ftDateTime, 0, false);
  ClientDataSet1.FieldDefs.Add(chk, ftBoolean, 0, false);
  ClientDataSet1.CreateDataSet();
  ClientDataSet1.Open;
  ClientDataSet1.Append;
  ClientDataSet1.FieldByName(id).Value := 101;
  ClientDataSet1.FieldByName(name).Value := abc;
  ClientDataSet1.FieldByName(dt).Value := Now;
  ClientDataSet1.Post;
  ClientDataSet1.AppendRecord([102,bbb,Now()]);
  ClientDataSet1.AppendRecord([103,ccc,Now()]);

 

内存表 ClientDataSet CreateDataSet

标签:

原文地址:http://www.cnblogs.com/cb168/p/4272477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!