Posts Tagged ‘4D v11’

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 »

Was doing a bit of 4D v11 programming when I discovered this conundrum. I found it to be confusing, but maybe it makes perfect sense to everyone else.

When showing a record to a user with the table in read only mode, 4D returns True for LOCKED even though LOCKED ATTRIBUTES returns nothing. This occurs only when using LOAD RECORD with a table in read only mode.

I would expect that 4D would not see this as a locked record, or return system information for LOCKED ATTRIBUTES. Further, when another process accesses this record in read write mode, 4D does not report this record to be locked, and it can be loaded modified and saved.

` "Save" button on a form in READ ONLY mode
` record is displayed in variables 
` with DIALOG command

$Event:=Form event

Case of 
	: ($Event=On Clicked )
		  ` first we need to make sure we can load the record
		  ` I would expect 4D to return false, since the table is in read only mode
		If (Not(Locked([Table])))
			  ` map the variables back to data values
			` instead I end up here with results 0, "", "", "" respectively 
			LOCKED ATTRIBUTES([Table];$process;$4d_user;$session_user;$process_name)
		End if 
End case 

However, if UNLOAD RECORD is execute after getting the data into variables the record is no longer LOCKED

Read Full Post »

%d bloggers like this: