Forum > Databases

[SOLVED] Question about Data Module

(1/5) > >>

1HuntnMan:
I'm relatively new to Lazarus.  On this app I started my first project, I started creating the main form and adding other forms which use a table(s), etc.  Got to reading about a Data Module so created one File-New-Data Module.  So, it appears to me that it's really just a form/unit. But, I am moving all the Data Tables and Data Sources over to it and every form that needs access to a table(s), just USING that form. It's working and I like that I have all the Data Table/Sources on just one form-Data Module.

Is that it or does a Data Module form have different code, etc. than just another form/unit added to your app. that's var name is DMPMS vs. FrmClientsMgt?

Also, on the Data Module I put all my table components on it, do I keep all the datasets there also or do I just put the DataSet component on the form that uses a table and point the dataset to the DMPMS.DbfPMS?

Thaddy:
TDataModule is about separation of responsabilities.
They work as a container for data elements that can be distinctly handled as a group. That can be databases, tables, queries etc. And also the datasets.
If your database application becomes more complex they will be become more important, but in principle they are not needed for simple solutions. They are simply a container, just like a Tframe.

1HuntnMan:
Okay, finished moving all table and datasets to the data module.  Compiles with no errors. But, when I attempt to run application without Laz active I get an access violation.

When I removed the TDbf components and the TDataSource components from all the forms except the DM, should I have left the DataSource components on the forms where the tables are referenced? So, for example if I have a DBGrid on a form, in it's DataSource property, I entered DataModulePMS.DSCategories. Would the correct way would have the DataSource on the form with the DBGrid and it's DataSource property pointing to the DataSource on the Categories form instead of the Data Module.  Would this be the issue?

Hansvb:
Take a look at the project source. Data module should usually be at the front of the uses list.

Thaddy:
No. In this particular case that does not matter.

Navigation

[0] Message Index

[#] Next page

Go to full version