Recent

Author Topic: [solved] GoToBookMark after closing & opening Query  (Read 3141 times)

kapibara

  • Hero Member
  • *****
  • Posts: 610
[solved] GoToBookMark after closing & opening Query
« on: February 17, 2014, 03:15:13 am »
Can Query.GotoBookMark(aBookMark) be called after closing and opening the Query?

Or will the bookmark pointer be outdated when the query is re-opened? I get a violation on trying this.
« Last Edit: February 18, 2014, 03:23:10 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: GoToBookMark after closing & opening Query
« Reply #1 on: February 17, 2014, 07:08:26 am »
Bookmarks must be handled as pointers after a dataset is closed they are probably invalid or pointing to the wrong record. In any case you need to find some other way to find your record, locate perhaps?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JZS

  • Full Member
  • ***
  • Posts: 194
Re: GoToBookMark after closing & opening Query
« Reply #2 on: February 17, 2014, 01:27:10 pm »
BookMarks will keep giving you violation if your data has been manipulated or re-fetched.

BookMarks as well as RecNo may not refer to the right records, IF, for instance, you are updating/deleting/reordering your records.

Locate should be your best approach.
I use recent stable release

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: GoToBookMark after closing & opening Query
« Reply #3 on: February 18, 2014, 03:21:42 am »
Thanks. Locate seems to be the best choice to find a record after closing the query.

If I understand correctly, Locate searches the result of a Query and finds the record you look for, if it exists.
If the Query is assigned to a data aware control like a DBGrid, then the located record will automatically be the current record of the grid. And thats just whats needed.

Example:

aQuery.Locate('field_name', 'FieldValue', []);
« Last Edit: February 18, 2014, 03:24:48 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

 

TinyPortal © 2005-2018