Ney André de Mello Zunino
2006-07-18 00:38:33 UTC
Hello.
I have a very basic loop over a query object (TADOQuery) which is not
behaving as expected. It is contained in a member function which is
supposed to check whether any of the records contain a non-zero value in
a given column ("correlation"):
bool TdmMonteCarlo::checkCorrelation() const
{
aqOperations->DisableControls();
bool correlation = false;
int idCurrent = aqOperations->FieldByName("id")->AsInteger;
aqOperations->First();
while (!aqOperations->Eof)
{
if (aqOperations->FieldByName("correlation")->AsFloat != 0.0)
{
correlation = true;
break;
}
aqOperations->Next();
}
aqOperations->Locate("id",
AnsiString(idCurrent).c_str(),
TLocateOptions());
aqOperations->EnableControls();
return correlation;
}
The problem is that the last record is not being processed. In other
words, the /Eof/ property is becoming true just as the cursor moves to
the last record, not when it tries to go beyond it, as things normally
work. Does anybody have any idea of what could be causing this? I read
somewhere else that Eof might behave strangely when key fields are
modified, but the loop in question is a read-only one.
Thank you for any feedback.
I have a very basic loop over a query object (TADOQuery) which is not
behaving as expected. It is contained in a member function which is
supposed to check whether any of the records contain a non-zero value in
a given column ("correlation"):
bool TdmMonteCarlo::checkCorrelation() const
{
aqOperations->DisableControls();
bool correlation = false;
int idCurrent = aqOperations->FieldByName("id")->AsInteger;
aqOperations->First();
while (!aqOperations->Eof)
{
if (aqOperations->FieldByName("correlation")->AsFloat != 0.0)
{
correlation = true;
break;
}
aqOperations->Next();
}
aqOperations->Locate("id",
AnsiString(idCurrent).c_str(),
TLocateOptions());
aqOperations->EnableControls();
return correlation;
}
The problem is that the last record is not being processed. In other
words, the /Eof/ property is becoming true just as the cursor moves to
the last record, not when it tries to go beyond it, as things normally
work. Does anybody have any idea of what could be causing this? I read
somewhere else that Eof might behave strangely when key fields are
modified, but the loop in question is a read-only one.
Thank you for any feedback.
--
Ney André de Mello Zunino
Ney André de Mello Zunino