Wed, 18 Jun 1902 08:00:00 GMT
Adding List Items From Database Fields
On Mon, 17 May 1999 13:29:57 +0100, "Neil Trigger" <webmas...@jbsi.net> wrote: Quote>Hi there everyone. I'm in a bit of a spot. >I have made a database, that's fine... >I can access the first post (or the active one) in a selected field, but I >can't access the whole field at once. >I've included a screen shot to show you basically what I mean. >What I need to do is take all the information from one column and put it all >in one list box on the main form. >I have added more items to the list in the screen shot to help explain. >Is there a way to add the whole lot? >Do I need to use loops and if so how would that work? (the syntax)
To add the value of a field for all records in the table, you would need a loop. The loop would be predicated on the Eof property of the dataset component (TTable, TQuery, etc.). To ensure that the record pointer starts in the right place, call the First method prior to the loop. The Next method moves the record pointer to the next record. Call Next once per iteration of the loop. At each record in the table, use a TField reference to access the field. Get this reference using either the Fields property or the FieldByName method. Use the TField.AsString property to copy the data out of the field as a String. For each field value copied, call the TListBox.Items.Add method to add that value to the TListBox component's list. If desired, before starting the copy you can clear the TListBox of all current contents using the TListBox.Items.Clear method. begin ListBox1.Items.Clear; Table1.First; while not Table1.Eof do begin ListBox1.Items.Add(Table1.FieldByName('SomeField').AsString; Table1.Next; end; end; ////////////////////////////////////////////////////////////////////////// Steve Koterski "There are two kinds of pedestrians...the Technical Publications quick and the dead." INPRISE Corporation -- Lord Thomas Robert Dewar http://www.borland.com/delphi (1864-1930)
|