Recent

Author Topic: Small DBMS project and How to code  (Read 3286 times)

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #15 on: June 08, 2023, 09:53:35 pm »
NEXT QUESTION:
developing by spiral model:
Are there any known sequences, how to prepare/make the code from general to detailed?
Any books? sources?

For example: begin with dumb procedure like
Code: Pascal  [Select][+][-]
  1.  
  2. procedure showResult (var str:string)
  3. begin
  4. if str<>''
  5. then showMessage ('program is working')
  6. else showMessage ( str);
  7. end;
  8.  

then upgrade this with a procedure call from another place:
Code: Pascal  [Select][+][-]
  1. //module1 uses module2
  2. procedure CalculateResult (var a,b:integer)
  3. var
  4. c: integer;
  5. begin
  6. c:=a+b;
  7. showMessage (intToStr(c));
  8. end;
And so on...
Actually - make feature developing through refactoring...

Are there any described approaches and where to find them? Any keywords?

TRon

  • Hero Member
  • *****
  • Posts: 2506
Re: Small DBMS project and How to code
« Reply #16 on: June 09, 2023, 07:05:52 am »
Let's say there are three modules.
the first - of Form1
the second - say it "Interface Tuner"
the third - "forms processor"

how to call a procedure located in the third module, from the second module, telling it to process a form from the first module?

Module1:
- declare the type and variable in the interface section of the module

Module2:
- in the implementation section of the unit add Module1 and Module3 to your uses clause
- Somewhere in the implementation section make the call to the procedure that you talk about, example:
Code: Pascal  [Select][+][-]
  1. procedure Invoke;
  2. begin
  3.   Module3.DoSomething(Module1.VariableFromModule1);
  4. end;
  5.  

Module3:
- In the interface section add module1 to the uses clause
- In the interface section add the prototype for your procedure (for proto see example below)
- In the implementation section add your procedure, example:
Code: Pascal  [Select][+][-]
  1. procedure DoSomething(VariableFromModule1: TTypeFromModule1);
  2. begin
  3.   writeln('Performing DoSomething with VariableFromModule1 = ', VariableFromModule1);
  4. end;
  5.  

Small Free Pascal example attached.
« Last Edit: June 09, 2023, 07:08:10 am by TRon »

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #17 on: June 09, 2023, 07:31:13 am »
Module2:
- in the implementation section of the unit add Module1 and Module3 to your uses clause
Thank you for reply.

This might cause circular unit reference in some cases.
Is it a solution, to declare types in a separate module, to use it( uses.... ; ) in all three modules?
« Last Edit: June 09, 2023, 05:49:12 pm by Researching »

TRon

  • Hero Member
  • *****
  • Posts: 2506
Re: Small DBMS project and How to code
« Reply #18 on: June 09, 2023, 07:44:06 am »
This might cause circular unit reference in some cases.
In some cases, yes indeed (Not in the example you asked for though). Nice to read/see that you noticed.

Quote
Is it a solution, to declare types in a separate module, to use it( uses.... ;) in all three modules?
That is the only fallback solution in case the interface/implementation "trick" can not be used.

If you write very large applications then even that can become cumbersome as it is possible that you have overlooked this topic at first and later on you have to conclude that you did something wrong in the process thus the need to move variable and type-declarations around in order to solve the circular reference. It can not always be solved, though some people would argue that if you are unable to solve it then you have a logic error in your code (which is basically true). In such cases you would need to rethink/simplify your type definitions/code.

edit: consider using datamodules or use your own custom unit to store each and every variable. E.g. do not rely on declaring/using variables inside forms when not necessary. Basically what I meant to say with that  is do not do that for functional code other than for variables (directly) related to the form/GUI itself.
« Last Edit: June 09, 2023, 07:52:09 am by TRon »

Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #19 on: June 13, 2023, 04:45:34 pm »
QUESTION: Need an architectural solution:
How to organize UI and business logics(controller in terms of MVC) for this?
Should I use TPageControl for this?
Or may I use TPanel or TFrame preformatted for each case, to manipulate them with property "Visible" (Y/N)?


The DBMS will have D-MVC approach,
Where:
D - data stored in files or got from DB abstraction layer(for SQLite3)
M - internal representation of data regardless of storage
V - GUI for representation
Controller - like a dispatcher which will take data from source and deliver to UI.

There is a form for DMBS UI. there will be several representations (1:1, 1:n, N:M...)
In some cases same data will be shown in different form.

Actually:
GetInput: select specific representation AND check:
if (requested data allows this representation)
then (show specific form) and (parse with specific parser).

Should this be done as several objects with
parent: "DataPresenter"
child: DataPresenter_AsTable, DataPresenter_AsList, DataPresenter_AsText
Then each child object will know it's presentation components, data parcer and data converter to form.

Possibly another architecture:
DataPresenters(form and structure)
DataProviders (with parsers from txt, csv, xml files)






Researching

  • Full Member
  • ***
  • Posts: 121
Re: Small DBMS project and How to code
« Reply #20 on: June 13, 2023, 11:19:56 pm »
QUESTION:
How to make it work (php-like pseudocode):
Code: Pascal  [Select][+][-]
  1. foreach ArreyEntity as record {
  2.  //show frame with field, radio-cell and button
  3. }
In general: how to make a component be drawn on a form?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Small DBMS project and How to code
« Reply #21 on: June 17, 2023, 01:31:35 pm »
QUESTION:
How to make it work (php-like pseudocode):
Code: Pascal  [Select][+][-]
  1. foreach ArreyEntity as record {
  2.  //show frame with field, radio-cell and button
  3. }
In general: how to make a component be drawn on a form?
While in practice this could work by dynamically create, attach and thus draw components on the form, the approach is hurting more than solving problems, as you now have greater maintenance issue. Creating controls dynamically is way more cumbersome than in HTML, that's why Data Aware Controls were invented. This already implements classic MVC built-in, where Model notifies changes to View directly. You just attach a data source to the components, now whenever you change anything in the data source, it will notify the components to get the latest data and updates its own presentation. Controllers are basically implemented as event handlers. And there you go, complete MVC in a desktop GUI environment.

 

TinyPortal © 2005-2018