我在学习写工资系统,在关闭整个系统后出现以下错误:
Table1:cannot perform this operation on a closed dataset?
恳请大虾赐教,在线等待!!!另外,“增加记录”和“保存记录”代码如下:
procedure TRecForm.SpeedButton1Click(Sender: TObject);
var i:integer;
    noo:string;
    boo:Tbook;
begin
    if not DataT.Table4.Active then
        DataT.Table4.Open;
    if DataT.Table4.RecordCount = 0 then noo:='0';
    if DataT.Table4.RecordCount > 0 then
        Begin
            boo:= DataT.Table4.GetBook;
            DataT.Table4.Last;
            noo:=DataT.Table4.fieldbyname('EmpId').AsString;
            DataT.Table4.GotoBook(boo);
            DataT.Table4.FreeBook(boo);
        End;
    noo:=FloatToStr(StrToInt(noo)+1);
    For i:=1 to 5-Length(noo) do
    begin
            noo:='0'+noo;
    end;
    application.CreateForm(Taddform,addform);
    if AddForm.ShowModal=mrOk then
    begin
        case AddForm.RadioGroup1.ItemIndex of
        0:  begin
                DataT.Table4.Edit;
                DataT.Table4.insert;
            end;
        1:  begin
                DataT.Table4.Next;
                DataT.Table4.Edit;
                DataT.Table4.Insert;
            end;
        2:  begin
                DataT.Table4.Last;
                DataT.Table4.Edit;
                DataT.Table4.Append;
            end;
        end;
    end;
    Dbedit1.SetFocus;
    Dbedit1.Text:=noo;
    RecForm.Caption:='记录管理  记录数为:'+IntToStr(DataT.Table4.RecordCount)+'人';
    AddForm.Release;
end;procedure TRecForm.SpeedButton3Click(Sender: TObject);
begin
try
  try
    with DataT.Table4 do
    begin
      if not active then open;
      edit;
      Post;
    end;
  except
    Application.MessageBox('数据发生错误!!!请运行<维护>---><数据清理>菜单项!!!','提示框',mb_ok+mb_iconstop);
    abort;
  end;
Finally
  Application.MessageBox('数据成功保存!!!','提示框',mb_ok+mb_iconinformation);
End;
end;

解决方案 »

  1.   

    table4在edit或insert之前有打開嗎?application.CreateForm(Taddform,addform);
        if AddForm.ShowModal=mrOk then
        begin
            if not DataT.Table4.Active then
            DataT.Table4.Open;
            case AddForm.RadioGroup1.ItemIndex of
            0:  begin
                    DataT.Table4.Edit;
                    DataT.Table4.insert;
                end;
            1:  begin
                    DataT.Table4.Next;
                    DataT.Table4.Edit;
                    DataT.Table4.Insert;
                end;
            2:  begin
                    DataT.Table4.Last;
                    DataT.Table4.Edit;
                    DataT.Table4.Append;
                end;
            end;
        end;