var
i: Integer;
begin
//ADOQuery已打开
//在数据集打开的情况下新增加一个字段
with Self.ADOQuery1 do
begin
TDataSetDesigner.Create(Self.ADOQuery1);
try
Designer.BeginDesign;
//Keep Old Field
//保留旧的字段
Designer.DataSet.Fields.Clear;
for i := 0 to FieldDefList.Count - 1 do
begin
with FieldDefList.FieldDefs[i].CreateField(Self) do
begin
DisplayLabel := IntToStr(i);
end;
end;
//Add New Field
//增加新的字段
with DB.DefaultFieldClasses[TFieldType(2)].Create(Self) do
begin
FieldKind := TFieldKind(1);
FieldName := 'FieldName' + IntToStr(i + 1);
Name := 'FieldName1' + IntToStr(i + 1);
DataSet := Self.ADOQuery1;
end;
//用于做后续增加字段的标志
DesignerData := 'Design';
finally
Designer.EndDesign;
Designer.Free;
Self.RefreshListBox;
end;
end;
end;