clientdataset goto a record based on index

Posted on 2005-04-06
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
Question by:hibbidiji
    LVL 10

    Expert Comment

    Hi, you should use

    presuming that your index is named ID


    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]);

    LVL 11

    Accepted Solution

    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]), []);
    LVL 1

    Author Comment

    As I use nonsequential ids this answer best solved my issue

    LVL 1

    Author Comment

    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?

    LVL 11

    Expert Comment

    Is the sn field an integer?

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

    Author Comment

    I have since resolved it. it was my error.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now