4D v16Generic programming (without pointers) |
||
|
4D v16
Generic programming (without pointers)
Generic programming (without pointers)
In addition to the manipulations explained in the video, you should also note that: These exercises are set up to show one specific way doing things. Depending on your own habits and the standards of your company, you may use different ways of organizing, of naming fields and variables, of establishing an order for passing parameters, and so on. A method can receive up to 32 parameters (from $1 to $32). However, it is unusual to use more than 7 or 8 parameters. You should make liberal use of generic programming. The next section covers the use of pointers, which complements what we will see here. Generic programming also lets you reduce the length of your code by concentrating a series of functions within the same method where you pass several parameters.
In this video, we're going to learn how to call methods and use parameters. We'll cover pointer type parameters later on. The purpose of generic programming is to optimize development and to facilitate maintenance and portability. We've already used a simple call to a method (without parameters) in the "On Startup" database method where we called the NAVIGATION method. In the first programming lessons, we saw how to configure buttons according to the page selected in the navigation form. Now we're going to optimize this programming so as to keep only one method that is used for all the navigation buttons (All, Query, Order by, and so on).
It will receive 2 parameters:
We call this method as follows: In a button, we will call NAVIGATION_FUNCTIONS
NAVIGATION_FUNCTIONS("All";FORM Get current page) There are two ways to type the parameters of the method that is called, in other words, the NAVIGATION_FUNCTIONS method: You'll notice that to name parameters, we use the syntax $1, $2, ... $n to retrieve each parameter. To make your method easy to read, we suggest that you create local variables with explicit names where you assign the value of the parameters received. So it is better to write: C_TEXT($1;$Action) since we can declare several variables in a compiler directive of the C_TEXT type for simple variables. C_LONGINT($2;$PageNum) and to retrieve the value of $1 in $Action and the value of $2 in $PageNumber, you can just write: $Action:=$1 The rest of the method is an adaptation of what we already described in previous sections; namely, adjusting the action to the request and configuring it according to the page and thus the table chosen: We will use:
:($Action="All")
What about the information we need to replace?
When we cover pointers, then we'll replace what we have here with a more generic method. We can do the same thing with the Query button.
and, as we did before, replace FORM Get current page by the variable that we received. We're going to put a break point and check that we go to this method when the form is executed. If we click on "All", we see the method being executed but what we're specifically interested in is the stacking of the methods:
If we double-click on this method, the code appears that leads us to this point and we can see that the NAVIGATIONS_FUNCTIONS method was called (with the parameters: "All", FORM Get current page). The method was received. Here it received the parameters: $1 = "All", $2 = the page number--here it is page 1. Next, $Action is "All" so we're supposed to go to this part We will then:
When we get to Technician, if we search for those whose name contains "bon", we will find BONAPARTE. We can see that our method works correctly.
|
PROPERTIES
Product: 4D
HISTORY
ARTICLE USAGE
Self-training ( 4D v16) |