Dbcombobox saving Dice

Asked

Viewed 895 times

1

I’m new to Delphi and I’m doing a form where all the entrances are DBLookup. I need a Combobox to select whether the person has known parents or not. Example:

  • 0 - Has parents,
  • 1 - Does not have.

I can put this on DBCombobox but how do I update the bank with 0 or 1? The field is of the type varchar. With the DBLookupCombobox I would have to get the data from a sql, which is beside the point because it’s just two pieces of information.

  • which version of Delphi you use?

2 answers

2

The component ComboBox creates an index for each item you include in the list. In this case, if you create in the order you submitted in your question, the indexes would be 0 = "Has Parents" and 1 = "Does not have". After that just call the property ItemIndex of ComboBox to write in the database the option selected by the user, as the example below:

query.edit;    // edita o registro
query.fieldbyname('CampoDaTabela').AsString := IntToStr(ComboBox.ItemIndex); 
query.post;   // salva o registro
  • If the field is Integer you use AsInteger in place of AsString that would look like this: query.fieldbyname('CampoDaTabela').AsInteger := ComboBox.ItemIndex;

0

the most correct way would be to click on a button after all the changes or the registration is done where you can perform as follows.

query.append;  // inclui um novo registro no banco de dados
query.edit;    // edita o registro
query.fieldbyname('CampoDaTabela').value := valor do edit, combo, etc; 
query.post;   // salva o registro

or the not very correct way it would be to leave the field.

to perform this way in the onExit event of the combo put the same procedure above, validating whether it is inclusion or change, for the given field.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.