On the probability that there is no such method, I created the following. Feel free to use it. I decided to go against a datasource instead of a query or table object just to keep it fairly generalized.
procedure LoadComboBoxFromSQL(DS: TDatasource; FieldName: string;
ComboBox: TComboBox);
var IsActive: boolean;
begin
IsActive := DS.DataSet.Active;
if not IsActive then // If the dataset is not active, then make it active
DS.DataSet.Active := True;
DS.DataSet.First; // 1st record
while not DS.DataSet.EOF do
begin
ComboBox.Items.Add(DS.DataSet.FieldByName(FieldName).AsString); // Add field to combobox
DS.DataSet.Next
end;
if not IsActive then // If dataset was closed when we started, close it now
DS.DataSet.Active := False
end;
Basically, you provide the procedure with the datasource and field you want to load from. The combobox you want to load the data to. The procedure will copy the data to the combobox. Note that is the dataset was cloded at teh start, the procedure will open it, perform its tasks, close it. If the dataset was open, it will remain so.