02 Jun 2006 

This text was originally written while V2004 was the most current 4D-version.

Keep every piece of code at one place only …

Starting with 4D it's fascinating to have code attached to a form, and code attached to formobjects, and to have code globaly to be called from forms and formobjects.
Pretty soon, this gets a mess. Think about events and when they happen or hunting for a specific code-snippet. It makes no sense, distributing pieces of code at different places.
I've standardized on global manager_methodes as the only place to handle real code.

Start

Basis First parameter is a text, which names what should be done. Therefore $what:=$1. No parameter means default-behaviour like from a menu-call or a click on the run-rutton.

Enhancement

Calling oneself without parameters is a process-starter. case2.jpg Is $what empty, the method will either start a new process or show the running process and bring it to the front. Processstart looks like recursiv (Current methode name) and passes as first parameter "StartProcess" which will get $what. case3.jpg

Later it might look like this

case4.jpg Expanding only the frist level of a finished method looks like this:
no parameter, a process gets started. The process opens a window und runs the user-interface. When finished "StartProcess" clears up. Other parts of the methode handle "FormMethod", "ButtonClicks" and other services.

Recursion

Important: recursiv calls are part of the concept. "newMessage" e.g. is a service for different parts of the method. case5.jpgThe service "newMessage" gets called in On Load:

Concept

Trying to explain the concept with a graphic: there is only one projectmethod that contains everything, like start and end of a module, the formmethod including all formevents, button-actions and button en-/disable, every subservice specific for that module.case5.jpg

Processvariables

A positive sideeffect is, that processvariables – we need them for the forms – only live in this one methode. They are declared, initialized, filled with values and finally cleared up in this method only. Other methods ask this module-method for the content of a variable. This saves work, debuggingtime and helps avoid memoryleaks. This way processvariables now are nearly as efficient as local variables: they only exist in this method and at the end of the process, 4D will remove them from memory for me.

Later added

You remember not having pointers to locals? Before V2004.2 we didn't have pointers to locals, so this kind of writing code was impoosible before. I love V12 for keeping the state of expanded/collapsed. The count of parameters is down to 3 most of the time.

4D Themen: Berichte in Arbeit