How do I solve the “Cannot perform this operation on a closed dataset” with Borland Database Engine and a Delphi application? [closed]

被刻印的时光 ゝ 提交于 2019-12-05 20:57:41

As per your own comment, you were unable to open the database file because it was corrupt. Thus, the error in your case meant not that you forgot to open it, but that your app cannot open the corrupt .dbf file.

Other not-so-obvious reasons why you might get this error, than the obvious thing that you failed to set the table Active property to true, include system or BDE configuration errors (ODBC or ADO, or other BDE runtime files missing or not configured) that are required to open the file

Error message says, that your dataset is not open. Seems you forgot to Open it or you Closed it somewhere.

If you run your application Delphi will restore the open or closed state that the dataset had in the Delphi form designer.

If there is an error Delphi can quitly drop this and close the dataset.
Also it's possible that you accidently closed the dataset in the designer, after with it no longer auto-opens on ptogram start.
When it's time to use the dataset you will get this error because the dataset is closed.

One option is to explicitly open the dataset in the FormCreate event and add error handling code there, this will allow you to see the error message and debug from there.

procedure TForm1.FormCreate(sender: TObject);
begin
  try
    MyDBFTable.Open;
  except on exception e do 
    WriteErrorToLogFile('Cannot open MyDBFTable, error is: ' + e.message);
    // or 
    //ShowMessage('Cannot open MyDBFTable, error is: ' + e.message);
  end; {try}
end;

I always do opening of datasets explicitly in FormCreate because this allows me to log any errors. If a client app has an exception it gets emailed to me automatically.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!