I set up a basic one-to-many pair of tables in a database (a Borrower
can have many books, a Book
can have only one borrower). I have a form to add a Book
, with edit boxes for other fields and thought I could use a DBLookupComboBox
for a Borrower
field. It should dropdown Borrower names, and when the user clicks Save
, the new Book
record should include a Borrower ID
(matching the displayed Borrower
name).
I set the combo box's
`DataSource` to the `Book DataSource`
`DataDield` to `BorrowerID`
`ListSource` is the `Borrower DataSource`
`ListField` is `BorrowerName`
`KeyField` is `BorrowerID`
The combobox displays the expected list of names.
The Save
event handler, I assume, should be something like
tblBook.Insert;
tblBook['Title'] := edtTitle.Text;
tblBook['Author'] := edtAuthor.Text;
// tblBook['BorrowerID'] := What goes here?
tblBook.Post;
What I find is that a new record is seemingly posted any time I change the DBComboLookupBox value. And I am unsure what's happening when I run the event handler.
question from:
https://stackoverflow.com/questions/65835874/how-to-use-the-dblookupcombobox-component 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…