This code is used in a Delphi form fmUserData, and is called on form.show, not create, to ensure data in combo box is up to date
The application uses MySQL server for data storage
cbucurr is a combo box in form fmUserData
// populate the strings list for the cbucurr combobox
fmUserData.cbucurr.items.clear; // make sure the combobox strings list is empty
fmUserData.qCurr.close; // qCurr is an ADO query linked to a table tCurr via an ADOConnection.
//My qCurr has a fixed SQL Select string that selects all currency codes, but you could insert a
// runtime select statement into the SQL.text property of qCuirr here
// My fixed SQL string is simply ‘Select currcode from tcurr’ ie I want all codes in tcurr
fmUserData.qCurr.open; // runs whatever select statement you have put in place
while (not fmUserData.qCurr.eof) do
// in above line, currcode is a field in the MySQL table tcurrr
I have the combobox set to uppercase and to sort the list automatically.
Hope this helps.