Recent

Author Topic: Locate current record after refresh...  (Read 611 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Locate current record after refresh...
« on: January 13, 2026, 03:52:59 pm »
Trying to return the record pointer back to the current record just posted. This doesn't error but just like doesn't execute:

Code: Pascal  [Select][+][-]
  1. procedure TFrmClientsMgt.QryClientsAfterPost(DataSet: TDataSet);
  2. var
  3.   CurID : Integer;
  4. begin
  5.   //=> Move back to the saved record...
  6.   CurID:= DataSet.FieldByName('CUSTNO').AsInteger;
  7.   QryClients.Locate('CUSTNO',CurID,[]);
  8. end;
  9.  

CharlyTango

  • Full Member
  • ***
  • Posts: 177
Re: Locate current record after refresh...
« Reply #1 on: January 14, 2026, 08:55:07 am »
In my opinion the record pointer stays at the same position when posting data. Why should he move?
Except when inserting data, the he should stay on the inserted record.

but maybe Bookmarks could help

Lazarus stable, Win32/64

Zvoni

  • Hero Member
  • *****
  • Posts: 3242
Re: Locate current record after refresh...
« Reply #2 on: January 14, 2026, 09:59:08 am »
In my opinion the record pointer stays at the same position when posting data. Why should he move?
Except when inserting data, the he should stay on the inserted record.

but maybe Bookmarks could help
Remember, that type TBookmark is deprecated/should not be used anymore.
Use TBookmarkStr instead
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Locate current record after refresh...
« Reply #3 on: January 28, 2026, 09:33:23 pm »
I tried TBookmarkStr instead per Zvoni but check out the way I coded it. Laz is having a problem with AnsiString vs. Integer.

Code: Pascal  [Select][+][-]
  1. procedure TFrmApptsMgt.QryApptsAfterPost(DataSet: TDataSet);
  2. {var
  3.   MyBookmark : TBookmarkStr;}
  4. begin
  5.   //MyBookmark:= QryAppts.Bookmark;
  6.   UpdateTTLAppts;
  7.   //=> Move to the previously saved record...
  8.   //QryAppts.GotoBookmark(MyBookmark);
  9.   //QryAppts.FreeBookmark(MyBookmark);
  10. end;
  11.  

I commented out the lines so that app can compile. This errors because MyBookmark is assigned an integer value via the first line: MyBookmark:= QryAppts.Bookmark;

But, my previous code works in an app I coded a couple of years ago????




1HuntnMan

  • Sr. Member
  • ****
  • Posts: 423
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Locate current record after refresh...
« Reply #4 on: January 28, 2026, 09:34:28 pm »
Also, the record pointer returns to BoF because I refresh after I Post...

Sieben

  • Sr. Member
  • ****
  • Posts: 385
Re: Locate current record after refresh...
« Reply #5 on: January 29, 2026, 12:08:36 pm »
That's the problem - Refresh occurs after AfterPost is executed. You need to place the Locate in AfterRefresh.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

 

TinyPortal © 2005-2018