David,
You touch on a great number of things here. I'm going to speak to what I've
been doing with the idea of a 'form controller' as Doug mentioned.

BTW - the issue with the difference between what's returned by OBJECT Get
pointer and OBJECT Get name is actually even documented somewhere, though
someone told me about it at a Summit. Annoying.

Oh, and with respect to listboxes, I rely on LISTBOX GET ARRAYS to get the
pointers to those objects. Most of the time you can get the pointer
directly using OBJECT Get pointer(Object named), except when you can't. I
agree it's a bit inconsistent. OTOH it doesn't list the objects in a
subform either...

Basically I create a project method to manage all the objects in my forms.
I too am moving to the 'no process variable' approach though in practice
it's usually 'as few as possible' which is often none.

My basic template is this:

C_TEXT($1;$2;$action;$errMsg)
C_POINTER($ptrCurrent;$ptrObj)

$ptrCurrent:=OBJECT Get pointer(Object current)
If (Count parameters=0)
  $action:=OBJECT Get name(Object current)
Else
  $action:=$1
End if
  // ------------------------------------------

Case of
: ($action="formEvents")  //  all of them
  Case of // some specific form event
  : (Form event=On Load)

  : (Form event=On Outside Call) & (<>Quit_4D)

    CANCEL

  End case

   //  this is a good place to put code I want to do things like set
visibility


: (False)  ///// buttons /////
: ($action="btn_dosomething")

  //  code goes here

: ($action="")
: (False)  ///// fields /////
: ($action="")
: ($action="")
: (False)  ///// form objects /////
: ($action="")
: ($action="")
Else
  $errMsg:="Unknown action or object: "+$action+"\r\rForm Event:
"+4D_FormEvent_text+"  {"+Current method name+"}"
End case

  // ------------------------------------------
4D_ALERT ($errMsg;Current method name)


I put this method into every form object usually with no params. In that
case I determine what object is doing the calling at the top.

I put this method into the form method with the param "formEvents". This
routes all the form events to method as well an I handle them in the top
part. I haven't had any issues with events not bubbling up through the form
as you mentioned. OTOH I tend to enable only the form events I need and
that's rarely more than 5 or 6.

I like this approach a lot. It moves all the actual programming out of
objects which makes it much easier to see what's going on. I can drill into
an object as necessary without having to do it for every single object
(simpler). It's also easy to reference a common action from from multiple
objects or buttons: My_form_controller("do this") works just fine. This
also helps when trying to test these things. And since this method is
called directly from the object I get any information about the object I
need.

Since a form is almost always interfacing with a human I write the action
code to return a text based error message in $errMsg in addition to any
other error logging. 4D_Alert is a custom alert that does nothing if
$errMsg is blank. This makes it easy to feedback to the user right away.
And, if I duplicate an object I don't have to update the object script for
it to work correctly. If I forget about one I get the error message the
first time it runs reminding me. That makes setting up a big array of
buttons or such a whole lot easier.

When I have a subform I'll make a separate method for the subform. That
gives me the ability to execute any of the subform code from the parent
form using EXECUTE METHOD IN SUBFORM. 'But I can do that anyway' you say.
True. The difference is I'm executing the same code the subform object
would. For instance, a subform has a button named 'btn_cool' that does
something. I can execute the btn_cool code by clicking the button or from
code by

EXECUTE METHOD IN SUBFORM("subformObj";"subform_controller";*;"btn_cool").


I've also been playing with ways to automate building forms using c-objects
web area and mustache. It sounds like Canon is a lot further along in that
area though. Would love to see what he's working on.

One thing I've recently discovered is pretty cool involves duplicating
objects. In my case a database has an extensive permissions scheme that
controls table/field access/visibility by user group. So the forms all have
hundreds of IP vars used for the field labels (which are also user
configurable). I hate all those IP vars. Turns out it's very fast to loop
through the fields on the form (FORM GET OBJECTS) and if it's visible
duplicate a hidden text object, write the user defined label and move it
into place next to the field. That's no variables at all. I was surprised
how fast it is to do that- even uncompiled it's unnoticeable. Obviously
this will only work on forms that are pretty regular but it's a neat
approach.



On Sat, Jan 7, 2017 at 2:03 PM, David Adams <[email protected]> wrote:

> OBJECT Get name (Object current)
> OBJECT Get pointer (Object current)
> Do they? It depends.
>
> I also assumed that you could toss out object scripts completely and trap
> everything in the form method.
>
> Can you? It depends.
>
> Right, so now for my observations and questions. As I've already said I
> tend to misunderstand things as a necessary part of learning how they
> really work, so please tell me what I've got wrong.
>
> As a reminder, my forms have dynamically-bound "form variables" instead of
> process variables. (For those that don't know, you only get this feature by
> clearing out the variable name area in the object's property list.) Also,
> I'm striving to move the code out of scripts entirely. At this point, I'm
> doing a bunch with listboxes so I've ended up with some listbox-specific
> behaviors and questions. Oh, in case I come across as being kind of whingy,
> I'm not. I really like the new features and they're a pleasure to work
> with. After just a couple of hours I've made heaps of progress...and turned
> up a bunch of questions.
>
>
-- 
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to