Bootstrap

TClientDataset的字段动态添加

Delphi中TClientDataSet的字段添加

ClientDataSet做内存表导入数据

var
aDataSet: TClientDataSet;
begin
if(aFieldType = ftString) then
begin
with TStringField.Create(nil) do
begin
FieldName := ‘Field’+inttostr(j);
Size := 80;
Required := false;
DataSet := aDataSet;
DisplayLabel := aTitle;
DisplayWidth := 40;
end;
end;

   if(aFieldType = ftfloat ) then
   begin
    with  TfloatField.Create(nil)  do
    begin
      FieldName  :=  'Field'+inttostr(j);
      Required  :=  false;
      DataSet  :=  aDataSet;
      DisplayLabel := aTitle;
      DisplayWidth := 20;
    end;
   end;

   if(aFieldType = ftBoolean) then
   begin
    with  TBooleanField.Create(nil)  do
    begin
      FieldName  :=  'Field'+inttostr(j);
      Required  :=  false;
      DataSet  :=  aDataSet;
      DisplayLabel := aTitle;
      DisplayWidth := 20;
    end;
   end

  end;

aDataSet.CreateDataSet;

end;

上方代码的ClientDataSet是要先create了的。

;