Recent

Author Topic: Bring Unit Data to Form  (Read 470 times)

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 323
  • https://www.pustertal.org/de/pustertal/unteres-pus
Bring Unit Data to Form
« on: September 23, 2021, 03:16:53 pm »
Hello :),

I was wondering about the best way to put the data of a unit into a form. I'm looking for an elegant solution (so far unsuccessfully :( ), which is why I wanted to ask the pros :).

Currently, I pass an object of the Data class to the GUI class as a pointer.

My goal is to completely decouple the GUI class from Logic, so that all calculations etc happen in the unit and the GUI only fetches or returns data.
But my problem still lies with the interface.
What is the best way to pass the data ? What is the best way return data from the GUI to the Unit ? how can I restore old data if on the form "Cancel" is clicked (I can fetch from the database, but maybe there is a better way ? :)) ?

In short:
DATA(Unit) --> GUI(Form) -->
   Loop begin
      User does Something --> GUI returns Data --> DATA(Unit) Handles Data --> Unit brings new Data to GUI
   Loop end
DATA(Unit) --> Save Data

Example: Calculator with 2 fields Edit1/Edit2
1. user enters numbers in those fields
2. Gui passes numbers to Data unit
3. Data Unit multiplies the numbers
4. brings back result to GUI
5. GUI Displays Result


Thanks a lot for any suggestion :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

linnemann

  • New Member
  • *
  • Posts: 34
Re: Bring Unit Data to Form
« Reply #1 on: September 23, 2021, 03:33:36 pm »
Hi

Depending on your size and complexity of application I would recommend.

http://tiopf.sourceforge.net/

http://tiopf.sourceforge.net/Doc/PersistingObjectsAndRelationships/SimpleCollection/

This can be overkill for a small application + the learning curve to understand the Model-GUI-Mediator design pattern can be steep.
Well worth it to understand it though. Can be used without databases etc. plenty of examples to show how this is done.

If you want to keep it simple then using the "data-aware" components if using a database.

If its just data then this has some good answers but in delphi

https://stackoverflow.com/questions/2956164/how-to-pass-data-between-forms-in-delphi



Weitentaaal

  • Sr. Member
  • ****
  • Posts: 323
  • https://www.pustertal.org/de/pustertal/unteres-pus
Re: Bring Unit Data to Form
« Reply #2 on: September 23, 2021, 03:50:39 pm »
Thanks :)


If its just data then this has some good answers but in delphi

https://stackoverflow.com/questions/2956164/how-to-pass-data-between-forms-in-delphi


That is what i was looking for. My Structue is pretty much the same. :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

 

TinyPortal © 2005-2018