clientdataset goto a record based on index

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
LVL 1
hibbidijiAsked:
Who is Participating?
 
pcsentinelConnect With a Mentor Commented:
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
 
_Katka_Commented:
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
 
hibbidijiAuthor Commented:
As I use nonsequential ids this answer best solved my issue

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
hibbidijiAuthor Commented:
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
 
pcsentinelCommented:
Is the sn field an integer?

when you are retrieving the ID are you using ID:=integer(fieldListArray.Objects[fieldListArray.Selected]);
0
 
hibbidijiAuthor Commented:
I have since resolved it. it was my error.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.