Recent

Author Topic: Serviсing multiple datasets simultaneously  (Read 1487 times)

Tikani

  • New Member
  • *
  • Posts: 10
Serviсing multiple datasets simultaneously
« on: July 31, 2017, 10:34:07 pm »
I have an SQLite3 database file containing 2 tables, created with this DDL statements:
  • CREATE TABLE objects(address TEXT PRIMARY KEY, ledger_account_number TEXT NOT NULL, management_company_name TEXT NOT NULL);
  • CREATE TABLE measurement_units(measurement_unit TEXT NOT NULL);
Further, I have 2 forms with DBGrids.
So, here comes the question - how can I follow the principle of reusability and bind datasets of each DBGrid with a single database communication point? I want to perform independend INSERT, UPDATE, DELETE operations at run-time in these DBGrids, but I don't want to produce extra entities in DataModule (separate SQLQueries for each DBGrid, for example)
« Last Edit: July 31, 2017, 10:38:00 pm by Tikani »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Serviсing multiple datasets simultaneously
« Reply #1 on: July 31, 2017, 11:14:33 pm »
If I understand your question correctly then you do something along the lines of
1) file\new
2) select Datamodule.
3)Drop an SQLConnection on the new datamodule
4)set it to talk to the database.
5)save datamodule under the name dmDatabase;
6)File\New->Datamodule
7)drop an SQLQuery.
8)Set it to access the Objects table do not forget the insert/update/delete and select sql statements.
9)save the datamodule under the name dmObjects
10)File\New ->Datamodule
11)drop an SQLQuery
12)set it to access the Measurement_Units table with the appropriate sql statements as well.
14)Save the datamodule under the name of dmMeasureUnits
15)file\new form
16)drop a dbgrid set it to all client. Name it dbgObjects.
17)drop a datasource. Name it dsObjects.
18)set dbgObjects.DAtasource := dsOBjects (use object inspector).
19)save the form under the name FrmObjectsGrid
20) set the dsObjects.DAtaset := dmObjects.SQLQuery1;
follow the steps 15~20 for a form with a dbgrid for the MeasureUnits datamodule as well.
open project\project options and go to forms if everything is auto created ee they appear on the auto-create forms list on left make sure that the first to be created is the dmDAtabase datamodule then the two dmOBjects/dmMEasuringunit in any order you like and then the two forms in any order you like.

That should give you enough flexibility for change ee you can change how or where the objects are read by making changes to the dmOBjects datamodule and as long as the field and component names remain the same you should not have to care about the grid forms, change the dmDatabase to talk to any database that has those two tables with their fields and so and so forth.

This way you preserve your IDE designer access and all that but your are flexible enough to change what ever needs to be changed in as the application evolves.

If I misunderstood something ask again.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018