0
votes

I have following code in Delphi 7 as well as in Delphi XE4. I am migrating my code from Delphi 7 to Delphi XE4. I am dealing with datasets.

My dataset dsABC is declared like following:

TfrmMainForm = class(TForm)
  dsABC: TpFIBDataSet;
  ......
  ......
end

dsABC is used like following at many places:

1. if (dsABC .Locate('ID', Id, [])) then   ---File 1
2. dsABC.Edit ----File 2

I mean to say, wherever it is used, its throwing this above said error in Delphi XE4 but same is working fine in Delphi 7.

But if I write following line before using dataset, it works fine

if not(dsABC.Active) then dsABC.Active := True;

I am forced to write this line in each and every file, and for each and every dataset in Delphi XE4 but I wonder then why its working in Delphi 7. Am I doing right to solve my problem or I need some default setting somewhere to get rid of this problem?

Is dataset in Delphi 7 by default active and inactive in Delphi XE4 and you have to explicitly activate it in Delphi XE4?

I found these links about this problem on stackoverflow, but nothing seems to be relating with my problem:

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

Cannot perform this operation on a closed dataset

3
"Is dataset in Delphi 7 by default active and inactive in Delphi XE4" Have you tried reading the source?MartynA
@MartynA - I have read the source code. By default it is inactive in the source code and is activated wherever required.user1556433
@Andy_D's answer sounds highly plausible to me. Anyway, what I would have done before posting here would have included: 1) explicitly opening the dataset in code and 2) setting up an event handler for the dataset's AfterClose event and setting a breakpoint on it. Then one could see what, if anything is causing the dataset to be closed before its next use.MartynA

3 Answers

4
votes

Given you've previously posted problems with connecting to the database (which would render any datasets left active at design time inactive) I would say that this is the root of your problem and highlights the problem with relying on datasets being activated in this manner in your code.

3
votes

There are some properties in TpFibDatabase for Designsupport:

DesignDBOptions -> ddoStoreConnected maybe these are set for delphi7 as default and not in Xe4

0
votes

Dataset was getting close because my transaction timeout was set to 1000 i,e one seconds. That's why dataset was getting closed after every second. I set timeout to zero to get rid of this problem.