Answer the question
In order to leave comments, you need to log in
How to properly use DBLookupComboBox to fetch data from a table (Delphi 7)?
There is an application from a DB on access from two tables. The application has two forms, each of which refers to a table.
The first table stores basic information (ID) with decryption (Name).
The second table is a slave. It stores information about the additional data described in table 1.
It is necessary to make sure that in the second form the "ID" field is filled out not by hand, but picks up the value of the "ID" field from the first table.
To do this, I used the DBLookupComboBox component, stuffed an additional ADOTable2 and DataSource2 onto the form to communicate with the first table.
Faced a problem. When I fill the DBLookupComboBox field with a drop-down list, the program creates a new entry in the table with this ID. And the remaining 3 fields, which are just text, go to the next line, i.e. in entry #2. Because of this, I can not make connections in the database (due to the fact that the key field is empty).
This results in a one line shift. How to make it so that all fields are recorded ONLY when the add button is clicked?
the code to fill is written:
procedure TForm2.Button1Click(Sender: TObject);
begin
ADOTable1.Insert;
ADOTable1['id']:=DBLookupComboBox1.Text;
ADOTable1['test1']:=Edit1.Text;
ADOTable1['test2']:=Edit2.Text;
ADOTable1['test3']:=Edit3.Text;
ADOTable1.Post;
begin
Edit1.clear;
Edit2.clear;
Edit3.clear;
end;
end;
Answer the question
In order to leave comments, you need to log in
I solved the problem as follows:
1. I created a separate button that creates a new (empty) line, and at the same time writes the value from this field.
2. left a record of the remaining fields in the second button. got this code:
procedure TForm2.Button3Click(Sender: TObject);
begin
ADOTable1.Insert;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
if Edit3.Text = '' then Edit3.SetFocus;
if Edit2.Text = '' then Edit2.SetFocus;
if Edit1.Text = '' then Edit1.SetFocus;
if (Edit1.Text = '') or (Edit2.Text = '') or (Edit3.Text = '') then begin
ShowMessage('Не заполнено поле!');
exit;
end;
ADOTable1['test1']:=Edit1.Text;
ADOTable1['test2']:=Edit2.Text;
ADOTable1['test3']:=Edit3.Text;
ADOTable1.Post;
begin
Edit1.clear;
Edit2.clear;
Edit3.clear;
end;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question