Recent

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

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #240 on: April 01, 2025, 09:15:43 pm »
Hi Benny,

A bit late, but I've actually been running into the following "issue" with the function:
Code: Pascal  [Select][+][-]
  1. function Execute(aMgr: ITransactionManager): boolean;
I almost never use the result and then i get a hint. It is not possible to add a second Execute procedure. That is seen as a duplicate.

I can suppress the hint or give a fictional result but there must be a better way.

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #241 on: April 01, 2025, 10:31:06 pm »
Hi Hans
Of course it's possible, just add it and I don't even think we'll need 'overload', 'cause they're function & procedure, so like this:
Code: Pascal  [Select][+][-]
  1. { specialized transaction, sports an 'execute' method, i.e.: it knows how to commit itself ;-) }
  2.   IhvbTrxExec = interface(IhvbTransaction)['{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}']
  3.     function Execute(aMgr: IhvbTransactionManager): boolean; {overload; ?}
  4.     procedure Execute(aMgr: IhvbTransactionManager); {overload; ?}
  5.   end; { IhvbTrxExec }
Should do just fine...
...and I'll add it to the tool too  ;)
If you feel like it, you can also just swap the 2 declarations and just have the procedure... The choice is yours mate =^
Regards Benny
« Last Edit: April 01, 2025, 10:35:00 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #242 on: April 02, 2025, 11:58:36 am »
Hi Hans
Quote
It is not possible to add a second Execute procedure.
You are absolutely right! Silly me  %)
Just got my ass handed to me by the compiler, for trying my original idea  ;D
So, I've found a flexible solution, it involves renaming the procedure to 'ExecuteNoRes' and at the same time, surround the 2 methods with compiler defines, that let you choose which one or both, you wanna use...
- Top of 'models.intf':
Code: Pascal  [Select][+][-]
  1. unit model.intf;
  2. {$mode ObjFPC}{$H+}
  3. {-$define dbg}
  4. {$define ExecRes}   (* these 2 controls which method(s) *)
  5. {-$define ExecNoRes} (* is/are in use in the IxxxTrxExec *)
  6. interface  ...
...and the definition part of the same unit:
Code: Pascal  [Select][+][-]
  1.   { specialized transaction, sports an 'execute' method, i.e.: it knows how to commit itself ;-)
  2.     at the top of this unit you can define which or both 'Execute(NoRes)' methods you want,
  3.     default is 'ExecRes' = ON, 'ExecNoRes' = OFF }
  4.   InewTrxExec = interface(InewTransaction)['{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}']
  5.     {$ifdef ExecRes}function Execute(aMgr: InewTransactionManager): boolean;{$endif}
  6.     {$ifdef ExecNoRes}procedure ExecuteNoRes(aMgr: InewTransactionManager);{$endif}
  7.   end; { InewTrxExec }
How does that look to you?!?
It seems to compile and run, but I'd appreciate it, if you'd test it a bit before I implement it in the 'MVP-Setup'  ;)
Thanks mate =^
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #243 on: April 02, 2025, 07:05:41 pm »
Hi,

I will test it but today and tomorrow i'll be home late. So i will take some time.

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #244 on: April 02, 2025, 07:29:35 pm »
Hi Hans
No worries mate, I'm in no hurry... :D
Can you live with the solution or not?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #245 on: April 02, 2025, 08:58:57 pm »
Hi,

If I understand correctly, there will be 1 function and 1 procedure and the ifdef determines which one is used in the transaction in question. Seems fine to me.

I was still thinking about the result. Actually, that is a nice way to be able to pull the handbrake in time. I will have to use that more often but will always keep transactions where that is not necessary. So your new setup is certainly useful.

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #246 on: April 02, 2025, 09:49:23 pm »
Hi Hans
Yup, that's about it =^
Yes, that's why I use functions in that setup, it has its usecases  ...and if need be, the result can be ignored...
But again you're right the warnings and/or dummies not so much...  ;D
Let's see how this flies...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #247 on: April 06, 2025, 11:17:43 am »
Hi Hans
Well, I just revisited this little conundrum, after it's stewed for while in the back of my head...
The cleanest solution is right in front of us...:
Code: Pascal  [Select][+][-]
  1. (* from model.intf.pas *)
  2.   { specialized transaction, sports an 'execute' method, i.e.: it knows how to commit itself ;-)
  3.     at the implementation you choose which or both 'Execute(NoRes)' methods you want }
  4.   InewTrxExec = interface(InewTransaction)['{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}']
  5.     function Execute(aMgr: InewTransactionManager): boolean;
  6.   end; { InewTrxExec }
  7.   { Note: remember to switch the GUID to a different one, if you copy/paste }
  8.   InewTrxExecNoRes = interface(InewTransaction)['{5E4DCDBA-8CB0-45E4-8DC3-6CD859DB4F1B}']
  9.     procedure Execute(aMgr: InewTransactionManager);
  10.   end; { InewTrxExecNoRes }
...and in 'model.decl':
Code: Pascal  [Select][+][-]
  1.   SGUIDInewTrxExec = '{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}';            //=^
  2.   SGUIDInewTrxExecNoRes = '{5E4DCDBA-8CB0-45E4-8DC3-6CD859DB4F1B}';       //=^  
I guess, that my subconscious found the other <Messy> solution </Messy>, somewhat lacking...  :D
Have a nice day & regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #248 on: April 08, 2025, 07:09:09 pm »
I will try that soon in the clean setup that your tool generates. In my existing project I have to change too much I notice.

edit:

I have it working now with "InewTrxExec" in a fairly bare setup. I had just started to rename ITransaction to INewTransaction but that is not necessary at all. I will see what happens if I also want to use InewTrxExecNoRes.
« Last Edit: April 08, 2025, 07:48:55 pm by Hansvb »

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #249 on: April 08, 2025, 08:13:22 pm »
I now have changed 1 transaction in my current project. The changes are much less than I initially thought.



Code: Pascal  [Select][+][-]
  1. model.inf
  2.  
  3.   { ITrxExec }  ==> Not changed
  4.   ITrxExec = interface(ITransaction)['{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}']
  5.     function Execute(aMgr: ITransactionManager): boolean;
  6.   end; { ITrxExec }
  7.  
  8.   { ITrxExecNoRes } ==> New
  9.   ITrxExecNoRes = interface(ITransaction)['{5E4DCDBA-8CB0-45E4-8DC3-6CD859DB4F1B}']
  10.     procedure Execute(aMgr: ITransactionManager);
  11.   end; { ITrxExecNoRes }
  12.  
  13.  
  14. model.decl
  15.   SGUIDITransactionManager = '{C75AE70E-43DA-4A76-A52D-061AFC6562D0}'; //=^     ==> Not changed
  16.   SGUIDITrxExec = '{2E618F58-DE15-4A79-ADEF-C4E0A7CBECA4}';            //=^     ==> Not changed
  17.   SGUIDITrxExecNoRes = '{5E4DCDBA-8CB0-45E4-8DC3-6CD859DB4F1B}';       //=^     ==> New
  18.  
  19. procedure TTransactionManager.CommitTransaction; = changed
  20. begin
  21. ...
  22.       prSaveChanges:          if fTrx.GetInterface(SGUIDItrxExec, lte) then begin  ==> Not changed
  23.                                 lte.Execute(Self);
  24.       end;
  25.       prCheckboxToggled:      if fTrx.GetInterface(SGUIDITrxExecNoRes , lte) then begin ==> changed
  26.                                 lte.Execute(Self);
  27.       end;  
  28. end;
  29.  
  30.  
  31.  
  32.  
  33. presenter.trax
  34.  
  35. An transaction....
  36.  
  37.  { TCheckboxToggleTransaction }
  38.  
  39.   TCheckboxToggleTransaction = class(TTransaction, ITrxExecNoRes)  ==> changed interface
  40.     private
  41.       Some fields...
  42.     public
  43.       procedure Execute(aMgr: ITransactionManager);  ==> New (was: function Execute(aMgr: ITransactionManager): boolean;  )      
  44.           ...
  45.          
  46.        
  47.  
  48.  

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #250 on: April 08, 2025, 08:26:38 pm »
Hi Hans
YES, that's exactly how I implemented it too, in my test setup...  :)
The 'new' in 'InewTrxExec' is just because I named the test project 'newtrx.lpr' and thus the 3 char id became 'new'. When I implement it in 'MVP-Setup', it will follow the already established 'xxx' prefix...
I thought this was a cleaner solution, than ifdef's all over the place  :D
Thanks mate, for testing and input \o/
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Hansvb

  • Hero Member
  • *****
  • Posts: 820
Re: Best way to exchange data between a form and a unit
« Reply #251 on: April 08, 2025, 08:39:56 pm »
This works well and is easy to adapt to an existing project. so.. good job. :D

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #252 on: April 08, 2025, 08:53:01 pm »
Thanks mate =^
Me Likey  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #253 on: April 09, 2025, 10:16:14 am »
Hi Hans
...and everybody else interested...
Version 12 of 'MVP-Setup' is out now, get your copy on GitLab.

Have fun & Happy Easter everybody  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

cdbc

  • Hero Member
  • *****
  • Posts: 2214
    • http://www.cdbc.dk
Re: Best way to exchange data between a form and a unit
« Reply #254 on: April 17, 2025, 11:31:17 am »
Hi Hans
Happy Easter.
<Spoiler Alert>
Tihi... Right, so first order on my Easter-TODO-List is finished, here's a teaser:
Code: Pascal  [Select][+][-]
  1. function TTransactionManager.StartTransaction(aModReason: ptrint): TTransaction;
  2. begin
  3.   if not InTransaction then begin
  4.     if fTraxClassMap.Contains(aModReason) then
  5.       fTrx:= fTraxClassMap.GetTransactionByReason(aModReason)
  6.     else case aModReason of { this is kept for now, maybe gone tomorrow :o) }
  7.       prCustom: fTrx:= TTransaction.Create(aModReason); // 1 ~ doen't cause an exception, 0 does!
  8.       prDataChanged: fTrx:= TTextEdit.Create(aModReason); // 1
  9.       /// etc...
  10.       else fTrx:= TTransaction.Create(aModReason); // 0 or anything undefined by us
  11.     end;
  12.   end;
  13.   Result:= fTrx;
  14. end;
</Spoiler Alert>
Have a nice day :)
Regards Benny

PS.: It's "Raining Cats and Dogs" here in Denmark :(
« Last Edit: April 17, 2025, 11:39:36 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

 

TinyPortal © 2005-2018