谢谢~~同上

解决方案 »

  1.   

    procedure AddCalcField(FdName: string; DSName: TDataSet; dt: TFieldClass);
    begin
      if DSName.FindField(FdName) <> nil then
        exit;
      DSName.Close;
      try
        with dt.Create(DSName) do
        begin
          FieldName := FdName;
          DisplayLabel := FdName;
          FieldKind := fkCalculated;      
          Name := DSName.Name + 'DSDesigner' + inttostr(DsName.FieldCount);
          index := DSName.FieldCount;
          DataSet := DSName;
          DSName.FieldDefs.Update;
        end;
      except
        on e: exception do
          raise Exception.Create(E.Message);
      end;
    end;