Recent

Author Topic: back visibility  (Read 1259 times)

amedeo

  • New Member
  • *
  • Posts: 39
back visibility
« on: March 27, 2022, 10:25:09 am »
Hy people
I have a question to change my application.
My application have a Main form from where I launch child forms by FormXxx.Show. In every child form there are declaration of Database (SQLite3), Transaction, Tabs e Datasets.
Is it possible to declare Database information in the  Main form and use its in the child forms?
I saw that calling Database function from a child form the Database is seen but not usable.
This is because my ignorance or is it a limit?
Thanks
Amedeo

Bart

  • Hero Member
  • *****
  • Posts: 5667
    • Bart en Mariska's Webstek
Re: back visibility
« Reply #1 on: March 27, 2022, 10:30:43 am »
Use a separate datamodule perhaps?

Bart

amedeo

  • New Member
  • *
  • Posts: 39
Re: back visibility
« Reply #2 on: March 27, 2022, 11:35:21 am »
Not, I do not use data-module just Tabs and Datasets

amedeo

  • New Member
  • *
  • Posts: 39
Re: back visibility
« Reply #3 on: March 27, 2022, 11:41:33 am »
... :-\ sorry ... I use Tabs and Query with Data-source  >:D

wp

  • Hero Member
  • *****
  • Posts: 13334
Re: back visibility
« Reply #4 on: March 27, 2022, 11:42:33 am »
Is it possible to declare Database information in the  Main form and use its in the child forms?
Never do this. Because it will create a circular dependence between the child forms and the main form: the main form needs to know the child forms in order to open them, and the child forms need the main form in order to access the datasets. Although Pascal can handle this if done properly, it is a very bad idea because you no longer can test the individual forms independently of the entire application. I recently wanted to convert a large Delphi application with about 50 forms to Lazarus; since each form depended on the main form the conversion can only be tested when everything is completed - I finally gave up.

Do what Bart told you: Add a datamodule to the project and put all the database components (connections, queries, datsets) on it. You can also put the TDataSource on it, but sometimes I find it more advantageous to have on the forms which need it.
« Last Edit: March 27, 2022, 12:00:00 pm by wp »

jcmontherock

  • Sr. Member
  • ****
  • Posts: 336
Re: back visibility
« Reply #5 on: March 27, 2022, 11:58:07 am »
You can create a common unit containing all the SQLite access. This unit could be included in all the forms accessing SQLite. That's not follow the OOP rules, but it works fine. I did it for an application multi forms with MySQL successfully. You have to play with some pointers between units.
« Last Edit: March 27, 2022, 12:16:18 pm by jcmontherock »
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

amedeo

  • New Member
  • *
  • Posts: 39
Re: back visibility
« Reply #6 on: March 28, 2022, 11:57:33 am »
Thanks
now I have a lot of mater to think about. ZEN meditation needs.
Amedeo

 

TinyPortal © 2005-2018