标签:
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