How to scroll randomly to any index or record number in Tsqlquery lazarus / 16-Databases ---------------------------------------------------------------------- heejit · 2018-12-03 10:55 is TSqlQuery.SetCurrentRecord is correct? ---------------------------------------------------------------------- mangakissa · 2018-12-03 12:06 Explain. Normally you use moveby() to jump to another record. Prior and Next are procedures to move 1 up or down. The best way is to use Locate(). ---------------------------------------------------------------------- heejit · 2018-12-03 12:20 moveby need distance that is move from current position to new position locate is for search record by field value I need to jump to a particular record number it is not related to the current position ---------------------------------------------------------------------- mangakissa · 2018-12-03 12:46 I still not understand what you looking for. Where is the particular record located? ---------------------------------------------------------------------- rvk · 2018-12-03 12:48 Yes, how do you determine what index-number to use? Index-number (or position) within a dataset is never a certainty. Closing and opening the dataset could result in a different position. If you got the index-position earlier (after opening) it might be best to use bookmarks. https://www.freepascal.org/docs-html/fcl/db/tdataset.bookmark.html ---------------------------------------------------------------------- heejit · 2018-12-03 13:29 Actually I am writing few small function for TSqlQuery to easy the access of field Index is parameter to function Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ASQLQuery.get_field(idx: Integer; cname: string): TField;begin  self.SetCurrentRecord(idx);  Result := self.FieldByName(cname);end; ---------------------------------------------------------------------- mangakissa · 2018-12-03 15:58 Scrolling to a record doesn't have to do with setcurrentrecord. Look at property fieldnames which is een TStrings where all fields are stored depending on the query. It has nothing to do with the location of the recordcounter. ---------------------------------------------------------------------- heejit · 2018-12-03 16:28 Ok is RecNo is the correct property ---------------------------------------------------------------------- rvk · 2018-12-03 16:44 Quote from: jshah on December 03, 2018, 01:20:31 pmI need to jump to a particular record number it is not related to the current position Maybe you can first explain what you mean by "jump to a particular record number"? How did you determine that particular record number? If it is a number/position saved from a different Open/Close session, you can't use that. You could use CurrentRecord (integer) with SetCurrentRecord but that only works within the same session (open/close). ---------------------------------------------------------------------- heejit · 2018-12-03 16:59 How did you determine that particular record number?  -Provide by user This is within open close of tsqlquery Flow as follow 1. Open tsqlquery with a select sql 2. move cursor to given record number 3. get the field data work on it 4. close the tsqlquery. ---------------------------------------------------------------------- rvk · 2018-12-03 17:42 Quote from: jshah on December 03, 2018, 05:59:34 pmHow did you determine that particular record number?  -Provide by user Then you definitely can't use CurrentRecord. That's something you can only determine and use after opening the table. You can't re-use it  once the table is closed !! You should search for the provided record another way. If the user wants a number you could create a field with a unique (autoincrement) number for that record and use that. Sqldb doesn't provide one. Even recno is not persistent for the same record once you close the table. ---------------------------------------------------------------------- heejit · 2018-12-03 18:14 I can use moveby moveby(0) moveby(given_index) ---------------------------------------------------------------------- rvk · 2018-12-03 18:20 Quote from: jshah on December 03, 2018, 07:14:50 pmI can use moveby No, you can't. If there is another record inserted or deleted after you determined your "given_index", the "given_index" doesn't point to the same record anymore. Try it, delete a record before that given_index and see if moveby still works to go to that record. If you want to make sure the same record is selected each time you need to use a unique identifier. Usually an ID field which is automatically increased with each insert. ---------------------------------------------------------------------- heejit · 2018-12-03 19:32 all sql is SELECT only  there is no change in record ---------------------------------------------------------------------- rvk · 2018-12-03 19:39 And what is the time-span between determining given_index and using it? If you are certain the table has not changed, you can use it. But normally, if it's user provided, it can change overtime. Records get deleted and inserted and your given_index is invalid from that point onwards. That's why I would recommend a dedicated ID field (like the whole SQL world is using). But if you want to use a static position, go ahead and wait until it goes wrong. ---------------------------------------------------------------------- heejit · 2018-12-03 19:47 there is no change between that it is immediate. One field from sql query Result will be display in list then user will select any item from list then I will take index and get the other field value of selected item and process it. ---------------------------------------------------------------------- mangakissa · 2018-12-04 07:37 Quote from: jshah on December 03, 2018, 05:59:34 pmHow did you determine that particular record number?  -Provide by user This is within open close of tsqlquery Flow as follow 1. Open tsqlquery with a select sql 2. move cursor to given record number 3. get the field data work on it 4. close the tsqlquery. In this case your scrolling in the dataset with a DBGrid. When the user insert/modify/delete a record SQLdb organise the changes automatically by indexkey (if available). When the user selects a record and goes to another form, take the current id and create a query with it. Why closing the dataset after each modification. ---------------------------------------------------------------------- rvk · 2018-12-04 07:43 Yes, if the data doesn't change you could do it that way. (Although I still think a dedicated ID field is a better idea.) But reading your description I wonder if a TDBListBox isn't a better choice. That way you can leave the dataset open and choosing a value will automatically place the dataset-cursor on the chosen record. ---------------------------------------------------------------------- heejit · 2018-12-04 09:39 I always like to fill data by code so I can control how I want to display data instead depend on sql query. if data is huge then only I use db aware controls