4D v16汎用プログラミング (ポインター不使用) |
||
|
4D v16
汎用プログラミング (ポインター不使用)
汎用プログラミング (ポインター不使用)
ビデオ中で説明した操作の他、以下の点にも留意してください: 例題では、特定のことを達成するためのひとつの方法を、あくまでも一例としてお見せしています。 開発者自身の慣習や会社の標準手法により、異なる方法、フィールドや変数の命名規則、引数の順番などは変わってくるでしょう。 ひとつのメソッドは32個までの引数 ($1 から $32) を受け取ることができます。しかし7個以上の引数を渡すことは通常ありません。 汎用プログラミングについては是非慣れ親しんでください。 次の節ではここで説明したことに加え、ポインターの利用方法について説明します。 特定の機能を汎用メソッドという形で独立化すれば、その機能を利用する各メソッドが短くなって、コードは見通しが良く、メンテナンスもしやすくなります。
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.
|
プロパティ
プロダクト: 4D
履歴
ARTICLE USAGE
セルフトレーニング ( 4D v16) |