One of the most neglected things I found on projects I have reviewed is progress dialogue for tasks, that run for more than a seconds. Although it is not always easy to estimate how long the task will run on production data, it is necessary to use progress dialogue as much as possible.
On the other hand, the badly designed dialogue could lead to major performance issues, so it is crucial to know how to work with dialogues.
Example
Let’s start with how dialogues are created. In C/AL language, dialogues are created using Dialog data type variable. From all functions that are defined for the Dialog data type, we use
- OPEN() function to open a new dialogue. It has one required parameter – text of the dialogue that could have placeholders to show a value from the UPDATE function or percentage value.
- UPDATE() to update the value of the dialogue. It has two parameters, the first one that specifies field we want to update (the number is defined as an order of the placeholders in the text that was used as a parameter for OPEN function). The second one specifies the value of the placeholder. If the function is called without any parameter, it just updates the dialogue, and so the application is in responding state (if we do not use UPDATE function and the loop took some time, the application just froze and the user may be notified about unresponding application).
- CLOSE() to close the dialogue.
So the easiest dialogue could be created with only these three lines. Before the loop, open the dialogue, update it in each run of the loop and once the loop is exited, close the dialogue (see the code below).
Local variables:
DialogVar (Dialog)
MyRecord (Record of any table)
--------------------
Code:
DialogVar.OPEN('My own text');
REPEAT
DialogVar.UPDATE();
UNTIL MyRecord.NEXT < 1
DialogVar.CLOSE();
We created a basic example of how to use progress dialogues. HOWEVER, this approach is really not ideal, and in loops with thousands of records, the impact on the performance will be significant.
The next article will describe how to develop performance-optimized progress dialogues and how to avoid some of the classic problems.