Encapsulate form/object methods with form event case statements

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.

C_LONGINT($vl_form_event)
$vl_form_event:=Form event

Case of
	: ($vl_form_event=On Load )  ` or other event
		  ` do code here
	Else
		  ` 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">
	<text>
		C_LONGINT($vl_form_event)
		$vl_form_event:=Form event

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

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


Author’s Note

Initial md Generated using https://github.com/jsr6720/wordpress-html-scraper-to-md

Original Wordpress categories: [‘4D’]

Original Wordpress tags: “4D”, “4D”, “4D v11”, “case of”, “clean code”, “form event”, “macro”

Original Wordpress comments: 1 Comment

Significant Revisions

tags: 2011, wordpress, txcowboycoder, 4D, 4Dv11, clean-code, event-handling

  • May 6th, 2024 Converted to jekyll markdown format and copied to personal site
  • May 3rd, 2011 Originally published on txcowboycoder wordpress site

EOF/Footnotes