Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table1.Next(); are Nuts????

Status
Not open for further replies.

luistsousa

Technical User
May 12, 2003
66
PT
HEllo guys

I don't know if Table1.Next() are nuts, but if not, I am by sure. The problem is this. I have a database in mysql with a column "stations". Inside I have station1, station2, and station3. With the code below I expect receiving the right result, but no. The program show an random result, like : station1, station1, station1. Or station1, station2, station1. Why?????

DataModule2.Table1.First();
for(i=0;i<3;i++){
// with !DataModule2.Table1.Eof the problem is the same

name=DataModule2.Table1.FieldByName(&quot;stations&quot;).AsString;
ComboBox1.Items.Add(name);
DataModule2.Table1.Next();
ShowMessage(name);
}
 
I cant really see what you are trying to do, but you dont need the double brackets after the call to Table1.First; Likewise for next. These should just be :-

DataModule2.Table1.First;
DataModule2.Table1.Last;
DataModule2.Table1.Next;
DataModule2.Table1.Prior;




When your feeling down and your resistance is low, light another cigarette and let yourself go [rockband]
 
Hi

The () came from builder. The problem is that I expect the following result : station1, station2 and station3. However the real result is completely random.

REgards
 
Assuming the data is in your table in the correct order (from your decription I assume it is) then the following code should work.
Code:
DataModule2.Table1.First;
ComboBox1.Items.Clear;
while DataModule2.Table1.EOF = False do
begin
  ComboBox1.Items.Add(DataModule2.Table1.FieldByName('stations').AsString);
  DataModule2.Table1.Next;
end;
I havent used MySQL but if the database is setup correctly and using a table component of any kind then something like this should populate your combobox.

As an aside, did you know that the ComboBox component has a handy &quot;Sorted&quot; value? Set this to true and the combobox will order its contents for you.


When your feeling down and your resistance is low, light another cigarette and let yourself go [rockband]
 
Hi

Believe or not, but with this way, only appear one record, the first (station1). I put this code in the function FormShow. The very strange is that I use this method a lot of times and never had problems.

Regards
 
Ok, I find. The problem is the if. With &quot;while&quot; works.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top