?
Solved

clientdataset goto a record based on index

Posted on 2005-04-06
6
Medium Priority
?
1,745 Views
Last Modified: 2010-04-16
if I have 25 records in a clientdataset and would like to goto the 3rd record how would I go about this?  

What I've done is built a tstringlist using a dataset as a source (looped through and concat'd some fields together to make a pretty list)  Now i'm using this tstringlist as the source for my listbox.  When someone clicks on the item I want it to get the index (got that) and go back and show another (not part of my tstringlist) portion of the data.  In PHP this would be dead easy with 3d arrays but in delphi I'm lost
0
Comment
Question by:hibbidiji
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:_Katka_
ID: 13724503
Hi, you should use

presuming that your index is named ID

 YourClientDataSet.Locate('ID',[IDnumber],[]);

Delphi syntax:

 function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;

you can also use multiple search conditions

 Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '831-431-1000']), [loPartialKey]);

regards,
Kate
      
0
 
LVL 11

Accepted Solution

by:
pcsentinel earned 2000 total points
ID: 13724558
When creating the stringlist, assign the ID field (which I presume exists) to the data of string

i.e. Stringlist.AddObject(Concatdata, pointer(IDField.Value);

Then use the value to do the locate

Locate('ID', integer(TList.Objects[TList.ItemIndex]), []);
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 13731193
As I use nonsequential ids this answer best solved my issue

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:hibbidiji
ID: 13732933
Uh oh.  with my first data sample the above solution functioned properly.  In further testing its not performing properly at all.

What I'm looking for is for the tstringlist to have a sord of multidimensional array aspect:

item:  id=>1
         string=>this is some text
itemL id=>5
        string=>this is more text

Here is my code:

 feedlistarray.AddObject(tempstring, pointer(strtoint(clientdataset1.FieldByName('sn').asstring)));

This adds my concat string to the object and attempts to set its index to the db serial number (id)

Later however, when I'm scrolling down my list of data and checking the DB data vs the index, I'm seeing that the index in the stringlist is 100% sequential starting with 1 when my db data is sequential, skipping some numbers.  This corrupts my liniking method.  Any ideas?





0
 
LVL 11

Expert Comment

by:pcsentinel
ID: 13733852
Is the sn field an integer?

when you are retrieving the ID are you using ID:=integer(fieldListArray.Objects[fieldListArray.Selected]);
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 13734167
I have since resolved it. it was my error.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question