Board index » delphi » Delphi Newbie Needs a Clue

Delphi Newbie Needs a Clue

Hello,

I've just started using Delphi Desktop 2.0 for a database project as part
of my Master's Degree.  The project is a genealogy application, which will
print out tree diagrams, and allow for complex queries against the
database (when done, anyway).

It was easy to put together a simple application for scrolling through the
records, searching, and doing queries, but now that I want to make the app
more sophisticated, I'm having trouble finding information.

I have a form which shows information from three tables, using
master/detail TTable components.  There is one master table (PERSON) and
two detail tables (BIRTH and MARRIAGE).  There are two TQuery components,
which use the master table's data source.  One query finds all children
for the current person record, the other finds all spouses for the current
person record.  I'm using two TDBGrid components to display the results of
the queries (all spouses and children for the current person).  This all
works well, and was easy to do.

What I would like to have is a TDBComboBox for the spouses, where I can
display for each spouse Last Name, First Name, and Middle Initial.  Each
of these is a separate field in the person table, so the strings would be
constructed from the results of the marriage query.  Based on the current
spouse selected from the combo box, a TDBListBox would show the children
of that union.

I picked up several books on Delphi (Delphi for Dummies, Delphi in Depth,
Delphi Nuts and Bolts for Experienced Programmers), but am not finding in
any of them how to do this.  I think I need to write a method for the
OnDataChange event of the TDataSource for the marriage query, which will
populate the combo box strings using the fields returned from the query.

My real question is: what resource can I go to for information at this
level of detail in using Delphi to build a database app?  I hesitate to
drop down more $ for another book, if it is not going to be in enough
detail.  Also, where can I find a FAQ for developing database apps using
Delphi?

Any info is greatly appreciated.
Joe the Delphi Newbie
(LMegath...@aol.com or sande...@bachman.com)

 

Re:Delphi Newbie Needs a Clue


Quote
lmegath...@aol.com (LMegathlin) wrote:
> Hello,

> I've just started using Delphi Desktop 2.0 for a database project as part
> of my Master's Degree.  The project is a genealogy application, which will
> print out tree diagrams, and allow for complex queries against the
> database (when done, anyway).

> It was easy to put together a simple application for scrolling through the
> records, searching, and doing queries, but now that I want to make the app
> more sophisticated, I'm having trouble finding information.

> I have a form which shows information from three tables, using
> master/detail TTable components.  There is one master table (PERSON) and
> two detail tables (BIRTH and MARRIAGE).  There are two TQuery components,
> which use the master table's data source.  One query finds all children
> for the current person record, the other finds all spouses for the current
> person record.  I'm using two TDBGrid components to display the results of
> the queries (all spouses and children for the current person).  This all
> works well, and was easy to do.

> What I would like to have is a TDBComboBox for the spouses, where I can
> display for each spouse Last Name, First Name, and Middle Initial.  Each
> of these is a separate field in the person table, so the strings would be
> constructed from the results of the marriage query.  Based on the current
> spouse selected from the combo box, a TDBListBox would show the children
> of that union.

> I picked up several books on Delphi (Delphi for Dummies, Delphi in Depth,
> Delphi Nuts and Bolts for Experienced Programmers), but am not finding in
> any of them how to do this.  I think I need to write a method for the
> OnDataChange event of the TDataSource for the marriage query, which will
> populate the combo box strings using the fields returned from the query.

> My real question is: what resource can I go to for information at this
> level of detail in using Delphi to build a database app?  I hesitate to
> drop down more $ for another book, if it is not going to be in enough
> detail.  Also, where can I find a FAQ for developing database apps using
> Delphi?

I'm still learning a lot from Pacheco's & Teixeira's excellent Delphi2
Developer's Guide, but you should browse it yourself to see if it
meets your needs.

Meanwhile, from your description, I think that you might want to use a
TDBLookupComboBox instead of TDBComboBox...

Good luck!

Jasper

PS: please take into consideration
- when replying, I just think I know;
- when asking, be sure that I don't.

Re:Delphi Newbie Needs a Clue


LMegathlin previously wrote an article appearing in comp.lang.pascal.delphi.databases:

Quote
>Hello,

Well, as an old Delphi hand (been using it since June), I can help some.
Our company bought a big stack of Delphi Books. A couple of good ones
are Delphi Unleashed and Peter Norton's book (forgot the title).

There are also a number of pretty useless books.

However, now that I've gotten my feet wet, I think that best books are
the ones that come with Delphi + the help files.

...

Quote
>I have a form which shows information from three tables, using
>master/detail TTable components.  There is one master table (PERSON) and
>two detail tables (BIRTH and MARRIAGE).  There are two TQuery components,
>which use the master table's data source.  One query finds all children
>for the current person record, the other finds all spouses for the current
>person record.  I'm using two TDBGrid components to display the results of
>the queries (all spouses and children for the current person).  This all
>works well, and was easy to do.
>What I would like to have is a TDBComboBox for the spouses, where I can
>display for each spouse Last Name, First Name, and Middle Initial.  Each
>of these is a separate field in the person table, so the strings would be
>constructed from the results of the marriage query.  

One of the nice things you can do with a TQuery is to create New fields.
Double click on the TQuery component go bring up the fields list, and
right-click on it to pop up the menu, select "New Field" and set the
new field to Calculated. You can then compute the value of the new
field in the OnCalcFields event. This is the most automatic way I can
think of (and having thought of it, I see how I can use it! ;-)

...

Quote
>My real question is: what resource can I go to for information at this
>level of detail in using Delphi to build a database app?  I hesitate to
>drop down more $ for another book, if it is not going to be in enough
>detail.  Also, where can I find a FAQ for developing database apps using
>Delphi?

Use the Help files. Unless you can find a book that tells you how do
exactly what you want, you will have to rely on your knowledge of
the properties and methods of the components available. So as you
use the components, look at their properties and think what they might
be useful for.

Kevin Davidson (ke...@qsinc.com)

Re:Delphi Newbie Needs a Clue


In article <4ue4kq$...@newsbf02.news.aol.com>, lmegath...@aol.com says...

Quote
> My real question is: what resource can I go to for information at this
> level of detail in using Delphi to build a database app?  I hesitate to
> drop down more $ for another book, if it is not going to be in enough
> detail.  Also, where can I find a FAQ for developing database apps
using
> Delphi?

I am also starting out in Delphi and writing a database app. I have two
books:
 Delphi 2 Developers Guide - Steve Teixiera & Xavier Pacheco
 Database Developers Guide with Delphi 2 - Ken Henderson

Both are by SAMS Publishing, Borland Press and both very comprehensive.
It says they are for accomplished to expert users but thankfully are
written in very plain english.

For your purposes, I'd highly recommend Ken's book as it covers extremely
well the whole process of developing a database app from Naming
Conventions through to Deployment.

Steve and Xavier's book is also an excellent reference to Delphi
functionality and development but with less emphasis on databases.

I wouldn't part with either.

Also here are some Delphi Web Sites to check out :
http://www.informant.com/delphi/di_index.HTM Delphi Informant Magazine
http://www.delphi32.com                      www.delphi32.com
http://www.components.clearcom.net/         Delphi Review Page
http://www.powerup.com.au/webmirror/delphi/  Delphi Super Page Index
http://www.electricdreams.com/ed2.htm        Electric Dreams - Delphi
http://www.doit.com/delphi/                  The Delphi Source
http://www.ortho.uab.edu/delphi/dw.html      Delphi World

Regards

Adrian

PS. Since we are similar stages of Delphi enlightenment, perhaps we can
help each other. Keep in touch if you wish

Quote
> Any info is greatly appreciated.
> Joe the Delphi Newbie
> (LMegath...@aol.com or sande...@bachman.com)

--
      _____  __  __________  ????????????????????????????????????????????
  /\       ) __) ___       | Adrian H. D. Bell      adb...@ozemail.com.au
 /  \     /    \ |_  |_ |_ | I.T. Contractor        
/    \___/ _____)|_________| SAP Systems Specialist Brisbane,   AUSTRALIA
    SAP Resource Centre  http://www.ozemail.com.au/~adbell/saprectr.html
?????????????????????????????????????????????????????????????????????????

Re:Delphi Newbie Needs a Clue


Quote
In article <4ue4kq$...@newsbf02.news.aol.com>, lmegath...@aol.com (LMegathlin) writes:

<snip>

Quote
>What I would like to have is a TDBComboBox for the spouses, where I can
>display for each spouse Last Name, First Name, and Middle Initial.  Each
>of these is a separate field in the person table, so the strings would be
>constructed from the results of the marriage query.  Based on the current
>spouse selected from the combo box, a TDBListBox would show the children
>of that union.

<snip>

Put the TDBComboBox on your form and assign the appropriate table (not sure
which one since I don't know what your table fields are). I think there is
a version of the TDBComboBox control that allows you to have multiple fields which
addresses your issue of Last Name, First Name, Middle Initial. If that doesn't pan
out, you could create a new computed field which is a concatenation of these
fields (select the TTable control on your form with the right mouse button
and select "Fields..." and create a new computed field).

IMHO, I don't think the TDBListBox is appropriate for the purpose you
are suggesting. Such an object is used to select a value for a field, not usually to
enumerate a list which is the result of a query (the list of children associated
with a set of parents would have to be obtained, I think, from a query on the
tables you currently have... but not sure since I don't know what your table
fields are or how your DB is designed). Sounds like you really want another
TDBGrid, but it will be smaller than your other ones since it doesn't need to
show that much info. A TDBGrid with one field looks an awful lot like a list box
anyway! You can even not show the field label at the top.

/Mark

Re:Delphi Newbie Needs a Clue


In article <4ue4kq$...@newsbf02.news.aol.com>, From lmegath...@aol.com
(LMegathlin), the following was written:

Quote
> I picked up several books on Delphi (Delphi for Dummies, Delphi in
> Depth, Delphi Nuts and Bolts for Experienced Programmers), but am not
> finding in any of them how to do this.  I think I need to write a
> method for the OnDataChange event of the TDataSource for the marriage
> query, which will populate the combo box strings using the fields
> returned from the query.

> My real question is: what resource can I go to for information at this
> level of detail in using Delphi to build a database app?  I hesitate
> to drop down more $ for another book, if it is not going to be in
> enough detail.  Also, where can I find a FAQ for developing database
> apps using Delphi?

OnDatachange is for record changes and Onstatechange is when the dataset
state changes from edit to insert, browse, etc...

Look in the on-line help, Mastering Delphi by Cantu, Delphi 2 unleased
by Calvert are also excellent books.  Placing showmessage in different
events is a neat way to learn how events fire and can help you in this
area.

God Bless,

--
Jay Schwisow j...@weldnet.com
08/14/96 01:13
---------
Using: OUI PRO 1.5.0.2 from http://www.dvorak.com

Re:Delphi Newbie Needs a Clue


Quote
> What I would like to have is a TDBComboBox for the spouses, where I can
> display for each spouse Last Name, First Name, and Middle Initial.  Each
> of these is a separate field in the person table, so the strings would be
> constructed from the results of the marriage query.  Based on the current
> spouse selected from the combo box, a TDBListBox would show the children
> of that union.

Investigate the TDBLookupComboBox - it would allow selection of records based on its value.  The
TDBComboBox allows selection from a set of values for a particular field.

Quote
> My real question is: what resource can I go to for information at this
> level of detail in using Delphi to build a database app?  I hesitate to
> drop down more $ for another book, if it is not going to be in enough
> detail.  Also, where can I find a FAQ for developing database apps using
> Delphi?

Resource?  Newsgroups ;-) My advice here is read all the on-line help you can.  I have taught
myself Delphi from the on-line help, it takes a bit of reading and experimenting but if you do
it this way, you pick up on a lot more knowledge in a wider area - making it easier to do other
stuff.

As to the OnDataChange, that can occur for every field, so its not the optimum place.  I would
consider using a stock TComboBox and concatenate the fields to build the list of values i.e.

combobox.items.add(table.FieldByName('LastName').AsString + ', ' +
table.FieldByName('LastName').AsString);

I would suggest putting the persons unique identifier in the string as well, to aid you in
locating the record.

You can detect a change in the combobox with OnChange, or OnClick.

Any more qs?  Mail me.

Re:Delphi Newbie Needs a Clue


Mark Pritchard wrote in a message appearing on comp.lang.pascal.delphi.databases:

Quote
>Resource?  Newsgroups ;-) My advice here is read all the on-line help you
>can.  I have taught  myself Delphi from the on-line help, it takes a bit of
>reading and experimenting but if you do  it this way, you pick up on a lot
>more knowledge in a wider area - making it easier to do other  stuff.

One of my programmers (who has been working on printing from the TRichEdit
component) came to me today and said that he had found a wonderful
source of information -- better than the help and better than the books.
That source was .... [mffrrm]

arghhh....

[Just kidding folks]

That source was the VCL source. There are very useful public methods
in the VCL source that are not documented in the HELP or the manuals and
the VCL source shows you how the insiders GET THINGS DONE.

--
Kevin (kwdav...@mercury.interpath.com) | http://www.interpath.com/~kwdavids/

* Respondeo ergo sum ("I respond, therefore I am"), Franz Bibfeldt

Other Threads