List Index is out of Bounds - Combo box problems

List Index is out of Bounds - Combo box problems

Post by carrie.ma.. » Fri, 23 May 2003 02:26:11



I need to load a combo box with a field from a table, I found some
code on-line but keep getting the List Index is out of bounds error. I
am new with Delphi but have some experience with VB. I am lost and
need to get moving on this. Please help me!!! Here is the code:

qry.close;
qry.sql.Clear;

qry.SQL.add('Select field FROM table');

try
 qry.prepared;
 qry.open;
except
 exit;
end;
try
 count := qry.recordCount;
except
 exit;
end;

combobox.Items.Clear;
for loopCount := 0 to pred(Count) do
begin
 combobox[loopCount] := dmrItemReports.qryReport.fields[0].asString;
 qry.Next
end;

qry.close;

Any ideas???????

 
 
 

List Index is out of Bounds - Combo box problems

Post by Dan » Fri, 23 May 2003 03:29:10



Quote:>I need to load a combo box with a field from a table, I found some
>code on-line but keep getting the List Index is out of bounds error. I
>am new with Delphi but have some experience with VB. I am lost and
>need to get moving on this. Please help me!!! Here is the code:

>qry.close;
>qry.sql.Clear;

>qry.SQL.add('Select field FROM table');

>try
> qry.prepared;
> qry.open;
>except
> exit;
>end;

OK to here; drop the counting bit next.
Quote:>try
> count := qry.recordCount;
>except
> exit;
>end;

[counting records is not needed here, and in general is not done
efficiently, or even correctly, in your app. The database engine is
better at it.]

Quote:>combobox.Items.Clear;
>for loopCount := 0 to pred(Count) do
>begin
> combobox[loopCount] := dmrItemReports.qryReport.fields[0].asString;
> qry.Next
>end;

>qry.close;

>Any ideas???????

Try this:
combobox.Items.Clear;
qry.First; // make sure you get all items
while not qry.Eof do
begin
  combobox.Items.Add(qry.FieldByName('fieldname').AsString);
  qry.Next;
end;

That should do it.
Dan

 
 
 

List Index is out of Bounds - Combo box problems

Post by Bruce Robert » Fri, 23 May 2003 03:05:42



Quote:> I need to load a combo box with a field from a table, I found some
> code on-line but keep getting the List Index is out of bounds error. I
> am new with Delphi but have some experience with VB. I am lost and
> need to get moving on this. Please help me!!! Here is the code:

> qry.close;
> qry.sql.Clear;

> qry.SQL.add('Select field FROM table');

> try
>  qry.prepared;
>  qry.open;
> except
>  exit;
> end;
> try
>  count := qry.recordCount;
> except
>  exit;
> end;

> combobox.Items.Clear;
> for loopCount := 0 to pred(Count) do
> begin

        ComboBox.Items.Add (dmrItemReports.qryReport.fields[0].asString);

- Show quoted text -

Quote:>  qry.Next
> end;

> qry.close;

> Any ideas???????

 
 
 

1. Bound list/combo boxes

Hello all,

      I am part of a team writing a VB/Access project and we are having
great problems getting our list and combo boxes to interact happily with
our database. Are there any list/combo boxes that can bind directly to
our database like some grids do? Any help would be appreciated.

Hugo

----------------------------------------------------------------------------

National Centre For Development Studies,   Phone:  +61 6  249 4704
Australian National University             Mobile: +61 15 958 305
Canberra, ACT 0200, Australia,             Fax:    +61 6  257 2886
----------------------------------------------------------------------------

2. Error Handling within stored procedure

3. Bound Combo-box Problem -- Help Please!!!

4. Query Status Dialog box needed.

5. Problems refreshing data from Data bound Combo Box

6. IIS,SQLserver connections help?

7. Bound combo, list-type problem

8. Front-End & Back-End

9. VB4 Pro Bound list/combo Controls Problems

10. adding to a combo box or list box

11. pls help : COMBO box or list box

12. List Box and Combo box