DataSet动态生成字段

procedure TForm1.Button1Click(Sender: TObject);
var
  j: integer;
  t: tstringfield;
begin
  query2.open;
  Query1.Close;
  query1.fielddefs.clear;
  for j := 0 to query2.FieldDefs.Count - 1 do
    with query2.FieldDefs.Items[j].FieldClass.Create(self) do
    begin
      FieldName := query2.FieldDefs.Items[j].name;
      Name := Query1.Name + FieldName;
      size := query2.FieldDefs.Items[j].size;
      Index := j;
      DataSet := Query1;
    end; // with
  Query1.FieldDefs.UpDate;
  T := TStringField.Create(Self);
  T.FieldName := 'myfield';
  t.FieldKind := fkcalculated;
  T.Name := Query1.Name + T.FieldName;
  T.Index := query2.FieldDefs.Count;
  T.DataSet := Query1;

  Query1.FieldDefs.UpDate;
  Query1.Open;
end;

你可能感兴趣的:(Integer,query,dataset)