More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Monday, 27 March 2017 3:20:05 PM(UTC)

Rank: Administration


Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

Locate vs FindKey and SetRange with a Delphi table or dataset

Delphi Locate vs Findkey

Delphi FindKey problem - FindKey doesn't work

Locate: Implements a virtual method for searching a dataset for a specified record and making it the active record. It returns false if not found. Common usage: Locate after SetRange - sets a broad range and then locate a specific record. eg.
DevTable.Locate('SYSTEMNO;DEVICENO;CHANGEDATE', VarArrayOf([FSysNo, FDevNo, FDateTime]), []);

FindKey: Searches for a record containing specified field values. If the search is successful, FindKey positions the cursor on the matching record and returns True. Otherwise the cursor is not moved, and FindKey returns False. Example usage:
If FindKey([SYSTEMNO, DEVICENO, CHANGEDATE]) then exit; exits if it doesn't exist.

SetRange: After a call to SetRange, the cursor is left on the first record in the range. Normalcy a range is more than a single record. It can be followed by First(), which may look like redundant, but in fact it may be not as it will set 1st record active. SetRange just sets cursor to the 1st record. It may not set the record active. Common usage: SetRange and then Locate as mentioned above.

In summary, firstly sets a wide range via SetRange, eg. the system range, DevTable.SetRange([SYSTEMNO], [SYSTEMNO]), then FindKey (key fields only) or Locate any fields, indexed or non-indexed.
Rss Feed  Atom Feed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.