Author Topic: Dataset navigation  (Read 2151 times)


  • Jr. Member
  • **
  • Posts: 64
Dataset navigation
« on: February 06, 2016, 06:14:15 pm »
I am writing a simple program that allows the user to navigate a table and display the records one at a time.  It is simple to move one record at a time or to the front or end of the dataset. 

I use the SQL command 'SELECT * FROM table_name' to load the information.  I would like to add a search function.

On the surface, this seems very easy using Select Where combo.  However, that does not do what I want.

I would like to have the internal record pointer of the original dataset moved to the resulting found record.  When I execute the Select Where I loose the original dataset.  It is easy to generate it again but I have now idea where the found record is.

I could code search of course but that is inelegant and resource intensive.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 824
Re: Dataset navigation
« Reply #1 on: February 06, 2016, 07:25:59 pm »
you can use the locate function of the TSQLQuery component :
Code: Pascal  [Select][+][-]
  1. function TSQLQuery.Locate(
  2.   const KeyFields: string;
  3.   const KeyValues: Variant;
  4.   Options: TLocateOptions
  5. ):Boolean; virtual;

example (in my database example image_mushrooms) :
Code: Pascal  [Select][+][-]
  1.  SQLQuery1.Locate('Common_Name','Death',[loPartialKey]);

on the form, in the DbGrid component, the selected record is the one which has the field Common_Name beginning with Death

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko


  • Jr. Member
  • **
  • Posts: 64
Re: Dataset navigation
« Reply #2 on: February 06, 2016, 08:52:09 pm »
Yes, that works brilliantly!  I actually tried using Locate before but I did not set the Options properly.

Excellent!  :)

Thank you!


TinyPortal © 2005-2018