The application was working perfectly, until I edited the user database (*.dbf) in OpenOffice.org Calc. Now it gives me the above error about a closed dataset.
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.
精彩评论