DBCombobox saving index

1

I'm new to Delphi and I'm making a form where all entries are DBLookup . I need a Combobox to select whether the person has known or unknown parents. Example:

  • 0 - It has parents,
  • 1 - Does not have.

I can put this in DBCombobox but how do I update the database with 0 or 1 ? The field is of type varchar . With DBLookupCombobox I would have to get the data of a sql , which is not the case because they are only two information.

    
asked by anonymous 05.02.2016 / 13:29

2 answers

2

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

query.edit;    // edita o registro
query.fieldbyname('CampoDaTabela').AsString := IntToStr(ComboBox.ItemIndex); 
query.post;   // salva o registro
    
20.02.2016 / 16:20
0

The most correct way would be to click on a button after all 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 when leaving the field.

To do this in the onExit event of the combo, put the same procedure above, validating if it is an addition or change, for the given field.

    
09.02.2016 / 15:25