Recent

Author Topic: MVP made easier.  (Read 6657 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #15 on: August 22, 2024, 11:52:59 am »
Thanks mate  :)
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: 710
Re: MVP made easier.
« Reply #16 on: August 22, 2024, 08:27:26 pm »
Hi,
I downloaded the zip file (and the tar file) with the code from gitlab. It appears that the istrlist contained in this zip and tar is not complete. The CreStrListFromFile function is missing. model.main does call this function and the setup tool does now compile now.
But if I replace istrlist.pas with the istrlist.pas from the foreach (bi langual) project, the setup tool will work properly straight away.

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #17 on: August 22, 2024, 08:46:12 pm »
Hi Hans
Thanks mate ;) I can't believe, that I make a new release and then forget the most important thing  >:( Stupid me  >:D
I'll get right on correcting that, sorry for the inconvenience  :o
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: 710
Re: MVP made easier.
« Reply #18 on: August 22, 2024, 08:48:46 pm »
Haha don’t worry.

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #19 on: August 22, 2024, 09:02:09 pm »
Hi
Right, so I think GitLab has finished updating by now...
Dang, it's a good thing you're awake, when I'm sleeping my day away  %)
Thanks again mate =^
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

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #20 on: August 27, 2024, 02:54:57 am »
Hi
Been dabbling with @Hansvb around i18n and implemented a couple of methods in the "product", that should aid in the dealings with multiple languages... Along the way, I've managed to make the 'DoEach' method robuster, in the sense, you don't have to remember(my achillesheel) to correlate with 'Sects' anymore, it's setup "automagically" for you...  8-)
As before get it here, the version is up to 10.26.08.2024
Have fun - Benny
« Last Edit: August 27, 2024, 02:59:56 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

Hansvb

  • Hero Member
  • *****
  • Posts: 710
Re: MVP made easier.
« Reply #21 on: August 27, 2024, 06:17:26 pm »
It seems like my learning curve keeps putting you to work.

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #22 on: August 27, 2024, 07:00:41 pm »
Hi Hans
Yeah, it does  ;D
But I'm happy, that you're working with it, gives us a 'real life' perspective, to work with/from... Way better than assumptions and anticipations  :D
The 'product' it produces keeps getting more and more practical and useful  ;)
All this is mostly due to your testing and asking questions, so please keep it coming  8) I think, for a /blank/ piece of "MVP-paper", it's getting quite good...
Thanks mate  :)
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: 710
Re: MVP made easier.
« Reply #23 on: August 27, 2024, 07:33:00 pm »
Haha, if you insist :), there is something else that I ran into yesterday. In the setup tool you use a dlgDirSel. The title is in the properties of the project inspector. So the title does not change if you set a different language. Because the dialogbox is not a view, it does not fit into one of the sects of the sects array.
In my own test tool I have something similar, an OpenFileDialog. I was thinking of putting all translations of this sort of components in the section view.main of sects. But then it probably gets confusing. (I haven't yet decided whether it is useful to put everything in the view.main section). I had the same thing with hints. I have added a separate section for hints. and then I do:
Code: Pascal  [Select][+][-]
  1. fPresenter.GetStaticTexts('view.configure.hints');   // get the hint texts
That works, but the hard coded
Code: Pascal  [Select][+][-]
  1. 'view.configure.hints'
doesn't sit well with me.
So one way or another I can get it to work, but I'm still not completely comfortable with it.

But, the tool you created works very well indeed. :D

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #24 on: August 27, 2024, 08:50:34 pm »
Hi Hans
I've got a few ideas for you, hang for a little while, gotta go see 'Young Boys' vs. 'Galatassaray' in champions league.
Then I'll write afterwards  :D
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: 710
Re: MVP made easier.
« Reply #25 on: August 27, 2024, 09:13:26 pm »
I'm not in a hurry. I probably won't continue until the weekend.

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #26 on: August 28, 2024, 10:24:39 am »
Heidiho...
Right, so the easy one first:
Quote
In the setup tool you use a dlgDirSel. The title is in the properties of the project inspector. So the title does not change if you set a different language.
I would go about it like this:
Code: Pascal  [Select][+][-]
  1. procedure TfrmEditDirs.SetStaticTexts(anObj: TObject;Texts: IStrings);
  2. var i: integer; lc: TComponent;
  3. begin
  4.   Caption:= Texts.Values[Name];
  5.   for i:= 0 to ComponentCount-1 do begin
  6.     lc:= Components[i];
  7.     if (lc is TButton) then
  8.       TButton(lc).Caption:= Texts.Values[TButton(lc).Name];
  9.     if (lc is TCheckBox) then
  10.       TCheckBox(lc).Caption:= Texts.Values[TCheckBox(lc).Name];
  11.     if (lc is TGroupBox) then
  12.       TGroupBox(lc).Caption:= Texts.Values[TGroupBox(lc).Name];
  13.     if (lc is TPanel) then
  14.       TPanel(lc).Caption:= Texts.Values[TPanel(lc).Name];
  15.     if (lc is TSelectDirectoryDialog) then begin
  16.       TSelectDirectoryDialog(lc).Title:= Texts.Values[TSelectDirectoryDialog(lc).Name];
  17.       TSelectDirectoryDialog(lc).InitialDir:= Texts.Values[TSelectDirectoryDialog(lc).Name+'.InitDir'];
  18.       TSelectDirectoryDialog(lc).Filter:= Texts.Values[TSelectDirectoryDialog(lc).Name+'.Filter'];
  19.     end;
  20.   end;
  21. end;
and mvptexts:
Code: INI  [Select][+][-]
  1. [view.editdirs]
  2. btnAddDir=&Add directory
  3. btnBrowse=...
  4. btnCancel=&Cancel
  5. btnRemDir=&Remove directory
  6. btnSave=&Save
  7. chbProjAsRoot=&Project as root
  8. dlgDirSel=Select Root Directory #<- HERE
  9. dlgDirSel.InitDir=/home/ #<- HERE
  10. dlgDirSel.Filter=Directories;Network #<- HERE
  11. frmEditDirs=Edit MVP Directories
  12. gbxDirs=Subdirectories (No . allowed)
  13. gbxProjName=Project Name (No . allowed)
  14. gbxRoot=Root directory (No . allowed)
  15. pnlBottom=(i) Db. click listitem to edit...
Will be back with more...  8)


Regards Benny
« Last Edit: August 28, 2024, 10:26:56 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

Hansvb

  • Hero Member
  • *****
  • Posts: 710
Re: MVP made easier.
« Reply #27 on: August 28, 2024, 06:56:59 pm »
I'm curious. I was trying with a dynamically created savedialog. Then you can only fill the title after creation and then I come to this:

Code: Pascal  [Select][+][-]
  1. In the view:
  2. procedure TfrmMain.mmiProgramNewFileClick(Sender: TObject);
  3. var
  4.   ...
  5. begin
  6.   ...
  7.   with saveDialog do begin
  8.     Title := fPresenter.GetStaticText('dlgCaption');
  9.   ...
  10. end;
  11.        
  12. In the presenter a new function GetstaticText (without s)
  13. function TPresenterMain.GetstaticText(const aText: string): string;  
  14. var
  15.   ldummy: integer;
  16.   statText: string;
  17. begin
  18.   fInternalMsg:= fModel.GetStaticTexts('view.main', ldummy); //
  19.   statText:= fInternalMsg.Values[aText];
  20.   result:= statText;  // returns the text voor the titel
  21.   // result:= fInternalMsg.Values[aText]; = shorter
  22. end;    
  23.  
  24.  
  25. in mvptexts.en
  26. [view.main]
  27. ...
  28. dlgCaption=Create new database file

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #28 on: August 28, 2024, 08:01:15 pm »
Hi Hans
Nice  8-) I like your solution, it's in the spirit of 'Supervising Presenter'.
Plus, if in a bind, one can always pack more values in a string and separate them with e.g.: value1|value2|value3  and the in the view use the 'Split' function to get an array of the different strings / properties...
With the foundation laid out, it's so easy to extend and build on ...once you understand the mechanics underneath it all =^
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

cdbc

  • Hero Member
  • *****
  • Posts: 1535
    • http://www.cdbc.dk
Re: MVP made easier.
« Reply #29 on: August 30, 2024, 03:28:07 pm »
Hi
Methinks it's time for another little example of working with the mvp-pattern, produced by 'mvp-setup', namely for those of you, who are as /lazy/ as I am  :D Here's an example of semi-automatic section registering, it touches 3 files after the initial creation with mvp-setup: model.intf, model.main & presenter.main.
we'll start with presenter.main:
Code: Pascal  [Select][+][-]
  1. ...
  2.  
  3. initialization                         { we're taking advantage of the fact, that }
  4.   RegisterSection(TregPresenterMain.ClassName); { 'Classname' is a class function }
  5.  
  6. end.  
  7.  
then model.main:
Code: Pascal  [Select][+][-]
  1.   { TregModelMain }
  2.   TregModelMain = class(TObject,IregModelMain)
  3.   private { remember to use 'RegisterSection' in units, you want to add to 'Sects' :o) }
  4.   const Sects: TStringArray = ('[view.main]'); //* cutaway: ,'[TregModelMain]','[TregPresenterMain]'
  5.   var
  6. ...
  7. constructor TregModelMain.Create(aPresenter: IregPresenterMain; const aRoot: shortstring);
  8. begin
  9.   inherited Create;
  10.   fPresenter:= aPresenter;
  11.   fRoot:= aRoot;
  12.   UpdateSections(Sects); { <- fetch our registered sections, v- i18n }
  13.   fTextCache:= CreStrListFromFile(format(mvpTexts,[fRoot,regLang])); ///<- i18n
  14.   { we need the model, this is a minor flaw if it fails, because then the }
  15.   if fTextCache.Count = 0 then { user will see a view filled with 'dummy' ;) }
  16.     fPresenter.Provider.NotifySubscribers(prStatus,nil,Str2Pch('(!) ERROR: Could NOT retrieve static texts!'));
  17. end; /// the above text can't be translated in the i18n'ed mvptexts, the count is 0! ///  
  18. ...
  19. {$EndRegion 'TregModelMain'}
  20. initialization
  21.   RegisterSection(TregModelMain.ClassName); /// <-- new in example, added        
  22.  
  23. finalization
  24.   if Assigned(Singleton) then FreeAndNil(Singleton); { checks for nil explicitly, freeandnil doesn't! }
  25. end.  
and finally the model.intf:
Code: Pascal  [Select][+][-]
  1. ...
  2.  
  3. {$interfaces com}
  4.  
  5. { registers sections for use in 'GetStaticTexts()', put it in 'initialization'
  6.   at the bottom of the unit, for the objects/units you'll be registering }
  7. procedure RegisterSection(const aSect: string);
  8. { gets called from model.main.constructor to update the 'Sects' array }
  9. procedure UpdateSections(var anArray: TStringArray); // <- - needs 'sysutils' added in top-uses
  10.  
  11. implementation
  12. uses contnrs;
  13.  
  14. var QSections: TQueue; { storage for our registrations till the model comes online }
  15.  
  16. procedure RegisterSection(const aSect: string);
  17. begin
  18.   if aSect = '' then exit; { no empty allocations }
  19.   QSections.Push(strnew(pchar('['+aSect+']'))); { enqueue the [section] for later update }
  20. end;
  21.  
  22. procedure UpdateSections(var anArray: TStringArray);
  23. var lai: integer; lp: pchar = nil;
  24. begin
  25.   if anArray = nil then exit; { we want at least '[view.main]' present before we start }
  26.   lai:= length(anArray); // start index for additions ~ 1
  27.   SetLength(anArray,lai+QSections.Count); { make room for all the registered sections at once }
  28.   while QSections.AtLeast(1) do begin { now as long as there are items in the queue }
  29.     lp:= QSections.Pop;                  { dequeue/pop the sections from queue }
  30.     anArray[lai]:= string(lp);                  { and add to array as a string }
  31.     inc(lai);                       { step our (l)ocal(a)rray(i)ndex 1 forward }
  32.     StrDispose(lp);      { now release the memory the string was being held in }
  33.   end;
  34. end;
  35.  
  36. procedure FinalizeQueue;
  37. begin
  38.   while QSections.AtLeast(1) do StrDispose(QSections.Pop); { clear the queue, jic }
  39.   QSections.Free; { free the queue }
  40. end;
  41.  
  42. initialization
  43.   QSections:= TQueue.Create;
  44.  
  45. finalization
  46.   FinalizeQueue;
  47.  
  48. end.
The reason, the registry is implemented in 'model.intf', is that this unit is referenced in every other unit's 'uses'-clause  ;)
Example project attached...
edit: Remember, 'TObject.UnitName' is also a class function, it's a nifty way of getting the unitname automagically...
Have fun & regards
Benny
« Last Edit: August 30, 2024, 03:43:03 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

 

TinyPortal © 2005-2018