4D v13

Video script

Home

 
4D v13
Video script

Video script  


 

 

In this video, we're going to learn about pointers and how to optimize their programming and make it generic.

As we saw in the previous exercise, setting options for each action (query, order by, etc.) in the NAVIGATION_FUNCTIONS  method can quickly become tedious. So, we need to set the action towards the table corresponding to the selected page.

In that case, it’s easier to indicate table to be used just once at the beginning of the method. We can store this directive in a variable and then use this variable in the commands.

Logically speaking, we can’t say that a variable is equal to a table; these objects are completely different and have completely different content as well. We’ve already learned that a variable can be an integer, number, text, picture, etc. It contains a value of the relevant type. A table isn’t “content” like a numeric value is.

The solution is to use a variable of the pointer type.

So we're going to set this variable, which is a local variable:

 C_POINTER($TablePointer)

This variable exists in memory. Now to assign a value, we'll use the following type of syntax:

 $TablePointer:=->[INTERVENTIONS]

So as we saw for variables, we have:

  • initialization
  • assignment of value

and, later on, wherever the Interventions table should have been used, we'll be able to replace it with this variable, that we'll need to "de-point" in this case.

The advantage being that all the code is here, a simple copy-paste with only a change of table, can be replaced by these 2 same lines of code, provided that we have previously set the table to where it must point depending on the page number.

So we have to get the code that we wrote earlier and here we indicate that:

  • If we are on page 1, we point to the interventions (->[INTERVENTIONS])
  • If we are on page 2, we point to the technicians (->[TECHNICIANS])

That said, we no longer need to test the pages here and so it's no longer useful to have this duplicate program.

We have a 1st program here that lets us:

  • set the table concerned depending on the page
  • and then set the action to perform regardless of the page since the correct table was set.

The same principle applies for searches:

  • we'll move the code here
  • completely remove the "Case of" that is here
  • and replace "intervention" with a pointer to the table since we are on page 2

When we get here, the pointer will be a pointer to "Technicians" and so we will search in the "Technicians" table.

The number of records found is the number of records found in the "Technicians" table.

 
PROPERTIES 

Product: 4D
Theme: Pointers