Chris:

"I prefer to reduce the number of Project Methods”
My thoughts about programming were strongly influenced by McConnell and a
few others. None of them discuss limiting the number of methods. Their
focus is on when and why to create a method and how those routines
interact. If reducing the number of methods is a desired attribute of code,
how do you know when you’ve got the right number?

"this same logic must be performed whenever City or Province changes.”
That’s sounds a lot like On data change in the GUI or using the Old
function in a trigger. Using the form controller approach, I put code in
each active object, Alternatively, you can put the code in the form method
but I ran into issues with not being able to trap events from tab controls
correctly so I decided to put code in each active object.

Here’s the code from an object:
C_LONGINT($formEvent_L)
$formEvent_L:=Form event

Case of
: ($formEvent_L=On Clicked) | ($formEvent_L=On Double Clicked)
PROC_FormEventValues_Assign (PROC_Object)
PROC_TablePtr_Set (PROC_Object;->[Ledger])
DISBURSEMENT_FC (PROC_Object)
End case

That code is put in place by a macro - all I have to do is change the
events to which it responds. PROC_Object is a process variable (gotta have
one).

The code in _Assign:

C_OBJECT($O_;$1)
$O_:=$1

  //OB Set is blowing up when assigned a nil pointer
  //PROC_FocusObjectPtr_Set ($O_;OBJ_FocusPtr_Return )
PROC_FocusObjectName_Set ($O_;OBJ_FocusName_Return )

PROC_CurrentObjectPtr_Set ($O_;OBJ_CurrentPtr_Return )
PROC_CurrentObjectName_Set ($O_;OBJ_CurrentName_Return )
PROC_FormEvent_Set ($O_;Form event)

PROC_gTablePtr_Set ($O_;gTablePtr_Get )

PROC_CurrentFormPage_Set ($O_;FORM Get current page)

C_TEXT($FB0521)
  //dvonroeder 20170201 {0521}
PROC_CurrentFormTable_Set ($O_;Current form table)

PROC_CurrentFormName_Set ($O_;Current form name)



That is then passed to a form controller method which reads the values in
the object and then dispatches the code.

Here’s the example code for the form controller

C_LONGINT($formEvent_L)
$formEvent_L:=PROC_FormEvent_Get ($O_)

C_TEXT($currentObjectName_T)
$currentObjectName_T:=PROC_CurrentObjectName_Get ($O_)

Case of
: ($formEvent_L=On Clicked)

: ($formEvent_L=On Mouse Enter)

: ($formEvent_L=On Load)

: ($formEvent_L=On Selection Change)

End case

PROC_FormEventValues_Clear ($O_)

Kirk’s presentation at the Summit showed using Form event inside the FC -
my preference is to pass a parameter. My argument is that using Form event
inside the FC increases the level of coupling. I have similar reservations
about the use of Form. but I do accept that it is called a “*form*
controller”, so there’s that…

This code pattern has worked quite well for me but I haven’t rethought
things in light of ORDA or dotted notation.

This does create large methods but they’re dispatcher methods, basically,
and it does supports the basic tenets of good procedural programming,
including the idea that a method should perform one specific function.

What strikes me about the approach that it sounds like you’re taking is
that you’re moving in the direction of larger method to satisfy a desire
for fewer methods. What’s the goal there?
--
Douglas von Roeder
949-336-2902


On Wed, Apr 24, 2019 at 9:37 PM Chris Belanger via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Hi Kirk,
>
> to explain what I want to have ‘custom events’ for, I think Justin Carr’s
> comment on this thread gives some good reason — to do processing after an
> on LOAD that cannot be done during that event since many objects on the
> form do not exist at the time of on load.
> In my efforts to create as generic of a system as possible (which OBJECTS
> help greatly in), some objects in a Form do not ‘exist’ during ON LOAD; but
> I need to initialize structures BEFORE the form starts operating and only
> at the initialization stage (on Load).
>
> Once 4D **finally** makes it possible to programmatically get/set all the
> listBox properties in a collection/entity selection-based listbox
> (particularly data source, current item, current item position, selected
> items) then I would be in position to make use of that information in the
> custom event that would run immediately after ON LOAD (as Justin described).
>
>
> Another use for it that I have not explored yet is to have a chunk of code
> that gets run under several different circumstances, but which I don’t want
> to make a dedicated Project Method for it.
> I prefer to reduce the number of Project Methods while, of course,
> creating ones that make logical sense (as they can be called in several
> places in my code). But you understand that as a programmer.
>
> One simple instance I want to experiment on — which, of course, is
> trivial, is:
>
> I have three fields (actually object attributes)
> City
> Province (or State)
> FullCityName
>
> FullCityName is computed from City & Province
> : (City = “”) —> FullCityName := “”
> :(Province = “”) —> FullCityName := City
> else
> FullCityName := City + “, “ + Province
>
> this same logic must be performed whenever City or Province changes.
> So it could be cool to set it as a ‘custom event’ that is ’triggered’ by
> City and Province scripts. Naturally, it would have to take place at the
> end of those scripts so as not to encounter unexpected behaviors.
>
> Now, it could be copy/pasted into both City & Province scripts; it could
> be made into a Project Method that gets called by either. Or it could be
> stuffed into the Form Method as a ’custom event’.
>
> ——
> I realize I am potentially playing with fire, as the execution of code
> could be much different than one is expecting if they don’t keep on their
> toes. The custom event will be handled after the code it is called from has
> completed execution. So under many circumstances it would be a bad idea.
>
> The example above is more of a ‘proof of concept’ for me.
>
> — Chris
>
>
>
> > On Apr 23, 2019, at 11:45 AM, Kirk Brooks via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
> >
> > Chris,
> > Reading through your post and the replies I'm trying to think of what a
> > 'custom event' would be. Can you give an example or two?
> >
> > On Tue, Apr 23, 2019 at 7:33 AM Chris Belanger via 4D_Tech <
> > 4d_tech@lists.4d.com> wrote:
> >
> >> I am wondering if there is a way to configure Custom Form Events. I
> would
> >> like to be able to post a form event, and have it then processed within
> the
> >> FORM METHOD as such.
> >> I am doing a lot of work in “Orda context” right now and can think of
> some
> >> handy features that could be implemented in that way, especially with
> >> keeping the number of project methods down (as code could be put into a
> >> script instead).
> >> Before you think “why would he want to do that?” — please just focus on
> >> the question of ‘can I?’. :)
> >>
> >> In the past, I used the form event “on Outside Call” stuff to handle
> >> communications between processes, so I understand all that stuff.
> >>
> >> I remember — but cannot find again — some documentation that talked
> about
> >> using negative-numbered values for events to facilitate custom events.
> >> However, I seem to remember it only was in the context of subforms.
> >>
> >> Any help or direction you could provide would be most appreciated!
> >> Thanks — Chris
> >> **********************************************************************
> >> 4D Internet Users Group (4D iNUG)
> >> Archive:  http://lists.4d.com/archives.html
> >> Options: https://lists.4d.com/mailman/options/4d_tech
> >> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> >> **********************************************************************
> >
> >
> >
> > --
> > Kirk Brooks
> > San Francisco, CA
> > =======================
> >
> > What can be said, can be said clearly,
> > and what you can’t say, you should shut up about
> >
> > *Wittgenstein and the Computer *
> > **********************************************************************
> > 4D Internet Users Group (4D iNUG)
> > Archive:  http://lists.4d.com/archives.html
> > Options: https://lists.4d.com/mailman/options/4d_tech
> > Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> > **********************************************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to