How do you create a data access layer?



Maybe this is another newbie question... :)

I've read that you really should have a abstracted data layer, to
decouple database accesses from the rest of your code. I'm not really
sure what this works out to in practice. Here's a guess:

Instead of putting a query in the FormCreate handler, you call a method
in a data module, say modUser.GetDataForUser(user_id, self) and the
method does the query, and fills in your components for you. But that
doesn't seem quite right. Does Delphi have a record object? Could the
method return a record containing the user's data, and then the form
could use whatever pieces of it to fill in it's own components? Do you
have to have a method for any possible query you might need? That
doesn't seem right either. What about joins over multiple tables?

I'm confused, I guess you can tell :) I don't have any experience with
this, and I barely know what a data module is...

Here's a hypothetical situation:
I have a form, and it needs to access 3 tables with a join in order to
get all the data it needs to fill out its components.

OK, so say the components are data aware (currently using a
master-detail relationship in the datasource properties), and the user
needs to be able to edit the data. How do you do that with a data
access layer?


Maybe this is too complex for a newsgroup. Is there a into-level book
or online tutorial on this subject? I've mostly found articles, and of
course articles don't go into much depth. Mostly, they've served to
convince me that I need to change my ways. :)

-Corinna

.