Recent

Author Topic: Best way to exchange data between a form and a unit  (Read 51682 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #165 on: April 08, 2024, 05:34:24 pm »
Hi
Code: Pascal  [Select][+][-]
  1.    _
  2.  ( ((
  3.   \ =\
  4.  __\_ `-\
  5. (____))(  \----   you're welcome :o)
  6. (____)) _  
  7. (____))
  8. (____))____/----
  9.  
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #166 on: April 14, 2024, 08:59:42 pm »
Hi,

Just as information.
I am now working on dynamically building components. This is done using a separate unit that is called from the model.
That all seems to work fine.
I still have some minor flaws when I abort a specific function, but I can't complain. (I'm figure it out).
This went better than expected.

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #167 on: April 14, 2024, 09:22:38 pm »
Hi
Quote
That all seems to work fine.
I still have some minor flaws when I abort a specific function, but I can't complain. (I'm figure it out).
This went better than expected.
Dang mate, this, I'm so glad to hear, Good on you  8-)
...and Yup, the model is king  :D allthough the presenter has a few tricks up its sleeve too  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #168 on: April 21, 2024, 05:28:58 pm »
It's weekend again so I'm doing some tinkering.

Quote
allthough the presenter has a few tricks up its sleeve too
I'll bite later :)

In the mainView I have placed a radio group with 3 options. I also have a number of stringgrids in the MainView.
Depending on the selected radio button, more or fewer columns are visible in the stringgrids. I do this switching on and off of the columns in the view. It's all visual, but I still doubt whether turning columns on/off shouldn't be moved to the Model. There will probably be more logic behind the radiogroup buttons later, which should certainly go to the Model.

What is wise?

Edit:
I think I already have my answer. I'm looking at one of the examples where you reset a progress bar. that's basically the same idea. it's all visual but still happens in the Model.
« Last Edit: April 21, 2024, 05:56:13 pm by Hansvb »

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #169 on: April 21, 2024, 06:41:13 pm »
Hi
Yup, that example seems to 'fit the bill', just had a look  ;)
Quote
allthough the presenter has a few tricks up its sleeve too
With that, I was mainly thinking of the 'TransactionManager' and friends...
One could say that, if Model is King, then Presenter is Queen(controlling the king)  :D
edit: Ps.: Tinkering can be a lot of fun & cool stuff, often comes from tinkering.
Regards Benny
« Last Edit: April 21, 2024, 06:48:53 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #170 on: June 22, 2024, 06:48:26 pm »
Hi cdbc,

An update from my side. I have now rebuild the tool that got me stuck in december conform the MVP setup. What i have so far works well. I don't see any error messages or AVs. That's probably because everything is now well separated. Well, most of it.
The only thing I still find difficult is choosing whether I go for a presenter/model or for the transaction manager/model. Both work great.

The pity is that I now find out that my tool idea does not work. It's not practical or the idea is worthless.
So I learned a lot (thanks again for that) and now I have to think of something new to make, even though I will continue to build a bit on the current tool.


cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #171 on: June 22, 2024, 08:43:42 pm »
Hi Hansvb
Quote
What i have so far works well. I don't see any error messages or AVs.
That's *so* nice to hear and I think you're right, the separation helps and gives you a more modular setup/overview of your application.
Quote
The only thing I still find difficult is choosing whether I go for a presenter/model or for the transaction manager/model. Both work great.
They both have their advantages, often I find it shows itself, which to use, especially if you develop a second 'View' (cli/web) in parallel, then it's nice to have options, so you can choose one that fits both/all views e.g.
...partly my fault, for 'pirating' transactions from databases and introducing the idea to you  :D ...I'm _not_ sorry, at all  8-)

Pity about your app, that sometimes happens, the /positive/ is, that it frees up your mind, to do other stuff =^ ...and you learned a lot.
Quote
...and now I have to think of something new to make
I've got an idea:
 How about a tool, that sets up the MVP-framework needed for an application. I mean, given e.g.: a root-path, a project-name, (your choice params) etc... It creates the skeleton dir-layout, the skeleton modules interconnected & a standard lpr-file, that you can open in lazarus and laz then creates the lpi and other files for a new project?!?
I think __that__ could be useful to a lot of people...  8)

All in all, Good on you mate, good job \o/\o/\o/
Thanks for the update  :)   ...and you're very welcome  ;)
Regards Benny
« Last Edit: June 22, 2024, 08:51:02 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #172 on: June 22, 2024, 11:02:01 pm »
Quote
How about a tool, that sets up the MVP-framework needed for an application

My programming skills are probably not good enough and my English could be better, but it's an interesting idea. I'll let it sink in for a while. Being able to easily set up a basic project is certainly useful.
Expectation management... I only have Windows so if I make something I can only do it on Windows.

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #173 on: June 23, 2024, 07:51:40 am »
Hi Hans
Your programming skills and your english are certainly good enough, from what I have seen, more than adequate  :)
Quote
Expectation management... I only have Windows so if I make something I can only do it on Windows.
That's the beauty about MVP, it's platform agnostic  :D Remember we shared projects without any frills and I only have Linux. The RTL is a great help in that respect.
After all, winders is an OS too, albeit a /niche/ one  :D :D :D :-X
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #174 on: June 23, 2024, 08:38:26 am »
Good morning,

I'll give it a try, but not right away, today. From the looks of it, the weather is going to be way too nice to sit in front of a PC.

Such a tool is also useful for myself. Should we start a new post for this?


My English is often Google translation  :)
I thought I had already seen that you had Linux but wasn't sure.

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #175 on: June 23, 2024, 09:09:06 am »
Good morning
True that, the weather is sunny here in denmark too and the wife wanna do some 'gardening'  ::) Think I'll build her a new garden-bank, weather should hold till friday \o/\o/\o/
Maybe a new thread/post would be nice, with a name that says what it's all about, but then again, it also seems some folks are following this one?!?
I'll leave it with you to find a suitable name, if you so decide...
Yeah, every time I start a new project, I miss a tool like that, just never got around to it  ;D
Sunny regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #176 on: June 29, 2024, 08:00:33 pm »
A first brief start. Only a project directory is created. That's all, but now I have a first draft of the units I can continue building with. (Progress will be slow, it's almost the holidays).
Next is creating the subdirectories. (that's more of the same). After that it gets more difficult.

Positive critical comments / improvements are welcome.   :D



cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #177 on: June 29, 2024, 09:03:08 pm »
Hi Hans
Me Likey  8-)
That's a good base to build on, let me play a little with it and I'll return with something...
Gotta go see Denmark \o/\o/\o/ vs. Germany in EM, I hope we can beat the Germans tonight =^
See you - Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: Best way to exchange data between a form and a unit
« Reply #178 on: June 29, 2024, 09:23:06 pm »
haha, i don't watch footbal.

I had already started with the sub dirs. Add a few as default via a listbox. (Got that from one of you’re examples). I'll wait for your answer first. Otherwise I might have to adjust too much.

Have fun watching the game.
« Last Edit: June 29, 2024, 09:38:51 pm by Hansvb »

cdbc

  • Hero Member
  • *****
  • Posts: 1645
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #179 on: July 01, 2024, 02:06:24 am »
Hi
Just some thoughts and questions...
* why do you send visual controls along into the presenter & model?
   in your reason-handler, you know which edit it pertains...
   they've got no business in there, except maybe as a source for errors.
* Use PathDelim from sysutils instead of hardcoded '\'.
Code: Pascal  [Select][+][-]
  1. function TModel.ProjectNameInRootDir(aData: TDirectoriesRec): TDirectoriesRec;
  2. var
  3.   ls: string; // (l)ocal(s)tring => avoids name-clash
  4. begin
  5.   if aData.dirPrjNameInDir then
  6.     ls:= aData.dirRoot + PathDelim + aData.dirProjectName
  7.   else           ///// this ^ instead of '\' or '/'
  8.     ls:= StringReplace(aData.dirRoot, PathDelim + aData.dirProjectName, '', []);
  9.                                ///// this ^ instead of '\' or '/'
  10.   Result.dirRoot:= s;
  11. end;
* Add '/' to check in location path for *nix.
Code: Pascal  [Select][+][-]
  1. function TValidateEntry.CheckFolderName(const aString: String): Boolean;
  2. const
  3.   Chars = ['0'..'9', 'a'..'z', 'A'..'Z', '_', '-', ':', '\', '/'];
  4. var                                            ///// add this ^ for *nix
  5.   i: Integer;
  6.   s: String;
  7. begin
  8.   Result:= True;
  9.  
  10.   s := aString.Trim;
  11.   for i := 1 to Length(s) do
  12.   begin
  13.     if not (s[i] in Chars) then begin
  14.       result:= False;
  15.       break;
  16.     end;
  17.   end;
  18. end;  
* the 'chkAddProjectToRootChange' event-handler is not consistent (yet),
   contemplating ...maybe 'ForceDirestories' could do the trick in model?!?
* the 'edtProjectLocationChange' event-handler gets called a *lot* and in a
   round-about sort of way, contemplating...
* is there a reason for not letting the 'view' show a dialog, before requesting
   the presenter to validate, instead of letting the model call back into the
   'view' / dialog area for getting a path and then letting the 'view' request
   validation from the presenter?
* would it perhaps make sense to have a 'TProjectProperties' or 'TMVPProps'
   class to hold all the collected and calculated values and connections,
   behind the scenes, instead of a record?
* you know, there's a clever way to get answers from the 'view' / user, in the
   model & presenter, namely:
   notify the observer -> let the reason-handler collect the info and
   return it via call-stack-unwinding  ;)
* color feed-back is cool, but looks a bit funny with white edit-background on
   a dark themed desktop  :D (the text-font is white)
*) contemplating means that I'm thinking about / 'sleeping on' input I can
    provide you with...
Do you have any specific needs, that I can help you with, it seems you have a good handle on things...  8)
Regards Benny
« Last Edit: July 01, 2024, 02:17:21 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018