Search code examples
delphidatasetdatamodule

Working with datasets in Datamodule


I have a DataModule and I want to have many (>50) datasets inside of it. I plan to request data from that datasets via functions and procedures.

The question is, what is the best way to organize datasets in the DataModule?

I see three options:

  1. One design-time component for each dataset.
  2. One common design-time component dataset for all datasets. Text of SQL command and other properties are set dynamically inside a corresponding function or procedure.
  3. No design-time components. Each dataset is created in the run-time inside a corresponding function, then it returns data to this function and gets destroyed.

How do you think, which way is the best? Or none of above? Are there any other ways to efficiently organize many datasets inside a DataModule?


Solution

  • I have used the following setup in the data module:

    1) Design-time components with design-time queries for:

    • data that will be present in your app for a longer time, e.g. data for user interaction like grids. Often with providers and clientdatasets concatenated to the query component.

    • datasets for repeated lookups (so usually with parameters)

    I gave them names referencing the entities that they were retrieving/updating. Clear for debugging and for other people.

    2) Design-time components without SQL for ad-hoc lookups and updates, usually just a generically named QryLookup and a QryUpdate. I just set the SQL at run-time and execute. Often without datasource etc.