Setting TMyQuery IndexFieldNames>"" changes current record

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Setting TMyQuery IndexFieldNames>"" changes current record

Post by NoComprende » Tue 27 Jan 2009 20:06

I'm using c++ builder (rad studio 2009). I'm finding that if I have a TMyQuery Q showing in a TDBGrid with
Q->IndexFieldNames="" and I click a button that programatically sets Q->IndexFieldNames="SomeField" then the current record is not maintained. The new top record becomes the current record but the AfterScroll event is not even triggered despite the change of record.

It only seems to happen if it's the first thing I do when the programme opens and the grid appears. If I scroll the grid before clicking the sort button the record indicator follows the current record to its new position after sorting. Subsequent sorts made on other fields also work as they should.

When sorting is working as it should the current record is often not 'centred' (as happens with the Locate method) after sorting.

NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Post by NoComprende » Wed 28 Jan 2009 11:26

The following code makes sure the record position is maintained and the record is centred

TBookmark Mark=Q->GetBookmark();
Q->IndexFieldNames="SomeField";
Q->GotoBookmark(Mark);
Q->FreeBookmark(Mark);

Also, GotoBookmark results in AfterScroll being called.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 28 Jan 2009 15:20

Was the problem solved?

NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Post by NoComprende » Wed 28 Jan 2009 16:22

Depends what you mean by solved Dimon. The second post is a workaround but the bug's still there (whether it's down to MyDAC or the borland TDBGrid I don't know).

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 30 Jan 2009 10:14

The point is that a just opened table stays in BOF state. Therefore when you set the IndexFieldNames property of this table, the cursor remains on the first record.
In order to solve this problem you should set the first record in the dataset after its opening, like this:

Code: Select all

Q->Open();
Q->First();

NoComprende
Posts: 135
Joined: Tue 09 Jan 2007 13:44

Post by NoComprende » Sat 31 Jan 2009 09:50

Thanks Dimon, I'll try it out later.

Post Reply