Posts Tagged ‘form event’

Clean code principle: run targeted code only once, even if multiple executions won’t ‘hurt anything’.

Make sure of this in 4D by encapsulating code with a Case of targeting specific events and turn off unneeded events.

$vl_form_event:=Form event

Case of 
	: ($vl_form_event=On Load )  ` or other event
		  ` do code here
		  ` should not have this event enabled then
End case 

This provides clarity on what code is to execute for the specified event. It also prevents code from executing multiple times if new events are selected for a form/object. I.e. enabling On Load with implicit On Click code already existing in the method.

I don’t type this every time I want to trap events. So I put the following in my macro file.

<macro name="CaseOf Form event">
		$vl_form_event:=Form event

		Case of 
			: ($vl_form_event=<caret/> )
		End case

*Note the above macro does not generate the given source, its just a starting point.

Read Full Post »

Default Setup
default form events

When creating a new form in 4D v11 it comes with a range of events ‘enabled’ (see figure). I’m assuming this is for ease of development.

However, I advocate for turning off all events first and then enabling specific events on an as needed basis.

4D will go into each form method and object method that has the event enabled and execute the method. When debugging this can be a real hassle because each event will trigger even if there is no ‘real’ code executed. 4D can’t tell what is in your methods and is just throwing events that the developer has specified.


Consider a simple form with a drop down chooser and two buttons. The form level On Click event does not have to be enabled for the object to throw the same event. However if there is code in the form method that is not protected by a form event case statement it will be executed in addition to the object method.

Form Design View

simple form

Form method

` executes on load and on click and whatever other events are triggered
` set a default choice for the array aTable (drop down chooser)

Object method

` executes on click

The object method goes first and gets the table name, but then the form method ‘resets’ the array location back to the first pointer. Moral of the story, wrap your code.

Read Full Post »

%d bloggers like this: