Re: Implementing combo box control linked to table
- From: "Paul E. Schoen" <paul@xxxxxxxxxxxx>
- Date: Wed, 18 Nov 2009 02:06:24 -0500
"BRoberts" <berdontemail@xxxxxxxxxx> wrote in message
news:dd050$4afd9a41$45c49ff1$10688@xxxxxxxxxxxxxxxxxxxx
"Paul E. Schoen" <paul@xxxxxxxxxxxx> wrote in message
news:88%Km.17007$de6.8358@xxxxxxxxxxxxxxx
// I am using a query to obtain the sorted list of IDs
procedure TReclData.UpdateTechIDs;
var Index: Integer;
begin
qTechs.Open; //tblTechs.Open;
qTechs.Active := True;
The above assignment is redundant. A call to qTechs.Open will "open" the
table if possible which will result in Active being set to true.
Alternatively, setting the value of the Active property will open or
close the table if necessary. Use only one of the above two statements,
not both.
Yes, upon closer reading of the Help, I found that Open also sets Active
True.
qTechs.First;
cbTechID.Items.Clear;
for Index := 0 to qTechs.RecordCount-1 do begin
RecordCount is not supported in all database types. A better, more
generic approach would be to use a While loop, e.g.
while not qTechs.EOF do
OK, I made the change, and I agree it is much better.
The following is a horrible bit of code that is completely unnecessary
given that the For loop is restricted to iterating only the number of
records in the table.
if qTechs.Eof then
break;
end;
qTechs.Close;
I think I added that because the RecordCount limit did not seem to work
right.
As another poster suggested, a far better solution to keeping the string
list copy of the table would be to query the id table directly.
I tried that first, but for some reason it didn't work. But I had a lot of
other problems so I might be able to succeed now. I was trying to emulate a
bound combo box as implemented in Access. The drop down box can have
multiple columns and you can navigate through the table. You can also enter
a few characters and it will find the first matching entry. But I don't
know how to generate a new record except by using a VBA function.
You might consider using a dbLookupCombo instead. Couple it with a button
to add a new id. The lookup combo will insure that only existing id are
ever selected. The button will allow a user to add new id as needed.
Using a button allows you to present a separate form for adding a new id,
which means simplifying your code and isolating functionality. If also
means that should you have several id fields on different forms, they can
all use the same form for adding new values with no recoding. The onClick
of such a button might look something like
/* presuming the add form is automatically created */
if addIdForm.ShowModal = mrOk
then begin
cbTechId.Refresh;
myDBLookUpComboBoxField.KeyValue :=
addIdForm.FieldContainingIdValue.Text;
end;
That might be a good option. I also thought about showing a dbGrid control
to provide means for editing other fields. But this application is supposed
to be for test technicians who are not always very computer savvy, and also
it is used in a shop environment where the operator may be wearing gloves
or have his hands full of oil, so simplicity is vital, and I may have to
look at ways to do everything using keystrokes rather than a mousepad. I
have a working system being evaluated by potential customers and I expect a
lot of feedback which will help fine-tune the application to their needs.
Thanks for the help on this project. Database programming is indeed
complex, and I feel as if I have just scratched the surface, but I think
now I know enough to do what is needed. Originally I was working with
someone who was supposed to provide the database interface, but after
countless delays and lack of response I decided to take on the project
myself. The original TCC program was an MSDOS app that he wrote using old
Visual Basic (probably similar to QBASIC), but now he has been working with
a programmer who is required to use .NET, even though he prefers Delphi and
actually introduced me to it almost 10 years ago.
This application has now grown in complexity and it needs a setup file
which I have created using Inno Setup. I learned a lot there, too, about
registry enties to set file associations and installing the BDE. I also
learned about default folders and how to make my program compatible with
Vista. When I tried my associate's program on my Vista machine, it locked
up and required a hard reboot. He claims he doesn't want to support Vista,
and that probably makes sense now, but I bet his app also has problems on
Windows 7.
If you want to check out my application, it is posted on www.Ortmaster.com,
along with an incomplete software spec. The program will run in demo mode.
I'm switching over to hardware mode now, troubleshooting a PC board that
interfaces a USB COM port over a digital isolator to the main portion of
the circuit which collects the data. I'm ordering 40 boards to be assembled
with a pick and place machine, and also ten steel enclosures. This is a
rugged device and I recently repaired an old version that had survived
being run over by a truck!
Paul
.
- Follow-Ups:
- Re: Implementing combo box control linked to table
- From: Maarten Wiltink
- Re: Implementing combo box control linked to table
- References:
- Implementing combo box control linked to table
- From: Paul E. Schoen
- Re: Implementing combo box control linked to table
- From: Paul E. Schoen
- Re: Implementing combo box control linked to table
- From: BRoberts
- Implementing combo box control linked to table
- Prev by Date: Re: Passing data from one form to another
- Next by Date: Re: Implementing combo box control linked to table
- Previous by thread: Re: Implementing combo box control linked to table
- Next by thread: Re: Implementing combo box control linked to table
- Index(es):
Relevant Pages
|