Summary of programming and debugging

zhaozj2021-02-16  51

Summary of program design and commissioning.

During the debugging process, many difficulties have been encountered.

1. I don't know how to pass an array in the function to do the arguments. I don't know how to define the shape in the function. I still use help to understand, officially discovering that F1 is very intimate, very good, just Not used. I think, learn how to use help can greatly reduce the cycle of learning.

The passage of array arguments is finally solved, and the array is to be defined in Type, as follows:

Type

Arr1 = array [1..100] OF INTEGER;

This defines an array type - ARR1, after declaring array as long as x: arr1; instead of x: array [1..100] of integer; in the array of arguments, only the number of group names is used as follows:

// Function Definition

Function F1 (X, Y: ARR1): REAL

Begin

.....

END;

// function use

P: = F1 (x, y); // x, y is two arrays.

2. During interpolation debugging, the algorithm is known, and the specific code debugging requirements are more careful. For the definition of variables, it is important to note that certain rules should be observed, otherwise there will be many unnecessary troubles in future maintenance and modifications, which may bring many unexpected errors, which will be described later. For algorithms that have been written in the book, it may vary depending on whether you have different bids (0 or 1), the starting point of the cyclic variable is different, and cannot be copied. Sometimes mistakes are often in a symbol (such as:> <, etc.).

3. For the function provided by Delphi, they have some prompts when they are used. For example, edit1. When you. It will list the methods you can use at this time. If you don't find the way you want to use, there is only two cases: 1 No method. 2 If you have a mistake in a certain place, this method cannot be displayed. For example: inttostr (edit1.text), in writing Edit1. After you can't find the text method. Because of the function errors, INTTOSTR () is integer value, but edit1.text is a string type, so it will not be displayed. Use this method to self-test.

4. Naming of variables is very necessary and useful, which is not detected in writing some applets. Because many variables are used in the applet, it is easy to manage, and you can remember with your mind, and you will not have a lot of trouble. In large procedures, especially multi-person completion procedures, your own defined variables may not know, so specification naming helps others and their own management and maintenance procedures. If the definition is unauthorized, it is possible to have unexpected errors. I met such a situation when I wrote Unit1. When writing a linear interpolation, an error occurs when the edge point is processed.

The error is like this: When the input point, press the interpolation button for the first time, there is no error. But when the button is pressed, this is why? Why do other interpolation do not have similar problems? I have conducted single-step debugging, and the place where the error was found is a loop variable error. When the second time is pressed, the loop variable changes, so that the result is wrong. At first glance, I originally I, and I use I to do global variables. Since the global variable is stored in the number of cycles, there is no I variable in the function, but directly use global variables instead of local variables. Such a local change affects the overall situation is the source of the error. Therefore, through this matter, I understand the importance of standard naming and annotation.

5. Implementation of exiting the process of Form is to pay attention to, if you have an operation of any form, if you have an impact, then you want to make a restore operation in calling the FORM, this is a must Work is also one of the important work. Pay attention to several aspects while writing to the Form's exit process: First, if you have to close the form, there are some visible components, such as Edit, Listbox, Label, Memo, etc., The content of these components recovers FORM just created, this is a must work. Don't underestimate this step, this is likely to bring you bundle. Most of the statements we call FORM are formx.show. And this statement only shows the form you want to call and does not do anything else, let alone an initialization work, so we have to initialize the form when you quit it, so that you can operate this time Lay the foundation. Otherwise, the data left by the last operation will continue to display in the Form, which affects our operations.

Second, in the writing of Form's exit process, pay attention to certain vulnerabilities, beginners are often easier to make such errors. For example: Everyone is often used to closing the window with form.close, this is right, sometimes we will make an exit button alone, call form.close, and restore this Form, all of which is normal. But when he uses the Form's own fork icon to close FORM, it will encounter trouble. When you enter again, you will find that there is no restore operation at the last exited, but the code of the restore operation is clearly written. Why is this? Because Form.Close comes only, the form is called, without other operations, the solution is to add to the restored code in the Form's onClose event. In the process code segment of the exit button added, you only need to use a show.close, restore it to the ONCLOSE Event.

Furthermore, when Form is closed, if there is a change to other FORM, you must restore, otherwise the error mentioned above will appear. Sometimes two FORMs have influenced each other, they are restored to each other. This is inevitable to use the Unit of the other FORM, with statements Uses UnitX; and this is also specified. In Interface, it is not possible to use each other. If Uses is in Interface, the system will report the version of Circle Use; so you can only be in the interface, another in the Implementation, or both in the Implementation.

6. Document sharing, this is a good way to reduce code quantity and reduce duplication of labor, reduce code redundancy. Specifically, write a public unit, put the functions, procedures, data, types, etc. of multiple forms, so that it is easy to manage and modify. In each of the Unit to use the function in this unit, you can go. However, it is important to write a statement for each function, the process can see these functions and processes. Otherwise, only the function is written in the Implementation, the process is implemented without writing, and they are only visible to this Unit, a little important. Remember, remember!

7. For naming rules, I will say a little more, take into account his logic when you name the variable. In other words, it is meaningful to give the name of this variable, which can let people know what he is doing. This is not only convenient for maintenance personnel management and maintenance, but it is also convenient for you to make a clear thinking, you can quickly determine the logical expression. In this regard, the representation of logical variables is the most obvious, such as: Defining a logical variable Flag, we can see that Flag is the meaning of marking. Then when there is a mark, we can write into if flag dam ...

Instead of writing if flag = true kil ... For the previous way of writing his logic, and easy to logical thinking. But beginners often use the latter way, which is not familiar with the type of Boolean, we have to develop habits. Try to make your own logic's logic, and comply with programming specifications, this will save us a lot of valuable time and effort to others. It is also necessary to make sense when giving a function of the function and the name of the name, so that it is not confused. I have encountered such a situation, in the Unit2 of the design, what is done about points, points are divided into upper and lower limits, these two definitions will have errors, if it is all wrong, if it is all wrong It is easy to correct, the upper and lower definitions are reversed, only the value becomes opposite. If a part is wrong, a part is right, then there is a default, such an error is often not judged from the error result, and can only segment the problem in the program. See if there is any error, so, it is very important to make a reasonable naming.

8. Steps in debugging work is to determine the wrong location, this work has been completed by the compiler. Sometimes the work completed by the compiler is just a preliminary, the specific location or requires us to find it. There are some wrong positioning because some reasons will be relatively large, and the lookups of these locations are to be able to find out the experience and careful observations. In practice, good writing habits will help us. Overcomes these actual error positions and error positions. In these errors, the more typical is: write or leak Begin or End, so that there is no pair, thereby causing the error. Sometimes it is pair; (), [] will also cause the same effect. Overcoming these mistakes is to develop good writing habits, such as: When writing programs, the statements typically in the same loop must be left to the left, and a two-cycle internal cycle is to zone. Difference to the external cycle. When writing Begin and End, you should write together. For parentheses (), [] is also the same processing, this is the advantage of writing together, there will be no missing another so that we don't need to remember the front when we write the program. Where else I used a begin, here I want to write an end and correspondence. This kind of benefit is especially useful when writing a function expression. In a more complex expression, if the number of parenthesis exceeds 3 floors, it is difficult to see, and a good writing habit will help you. You won't spend an eye in order to find another corresponding parentheses, as long as you write from the way in one step, it will not be too difficult. Of course, others have to understand that it will take a certain time, but you will not be wrong.

In addition to the positioning error, it is necessary to correct the error. Of course, however, the methods I will correctly correct the error, but the most effective is to read the compiler to your prompt information. This is what we look for the wrong starting point, some of whom can easily see, such as: variables have no declaration, before else, the type does not correspond, the function parameters are transmitted. Some errors can't be seen from the information. The syntax is not difficult to correct, but the error of the algorithm is not correct. This requires us to find an error step by step by debugging tool. The most commonly used tools are breakpoints, single-step entry, single-step jump, and observe variables. Breakpoint can help us segment the program and see that it is wrong to find it in that part. However, after debugging, you must remember all breakpoints, or your program will suddenly interrupted at runtime, and you can't find it wrong. I personally compare the use of single-step entry single-step jump out add watch This is a must of the debugger. The writing program is not difficult. The master of debugging is a very person, I have always thought. Single-step entry is a step-by-step debugging, while interpretation is running, so that we can find an error. Single step jump out is to help single-step entry, single-step jump out for a process or a function is a statement, and a bit jump over, which saves the correct partial inspection. You can also use this item running to the cursor, both of which are shortening the correct program segment. Add Watch is a very easy to use Dongdong, you can join the name of the variable you want to monitor. The value of the variable will be displayed in the table, and he cooperates with a single step, you can see whether the variable you want know is in the same change in each step. If there is an entry, you can analyze the statement, so that the reason is to find out. It can be seen that single-step operation add Watch is the necessary steps necessary to debug programs and the most effective way. However, when the program is more complicated, when the call function is more, it is not so easy to use. Because it is often useful in a button event, there are several procedure or function, and other function and procedure are often called in each Function or Procedure. Therefore, it is easy to use a single step to enter the dizzy steering, and I don't know the cloud. If you use a third-party control, you don't know where the program is running. Therefore, in a large amount of program, the single step operation is not easy to use. At this time, we'd better use breakpoint tools. The meaning of his use and single step operation is the same, just to see if the program is running according to our designs. The advantage of breakpoints is that he can make us suspended in a place where you want to stop, and the rest of the rest does not need to stop according to the original rate. Combined with Add Watch, we can see the process of running throughout the program. The increase in breakpoints is more quite, in general, in the following places: 1 The entrance to the cycle statement, add the breakpoint to monitor the data that enters the loop, see if it is There is an error before the cycle. Putting one before each cycle is like a backup, see what the result will be. 2 Set a breakpoint in the last sentence of the cycle statement, so that every loop process can be monitored, see if the loop is wrong. There is also a benefit to set up a breakpoint inside the loop to prevent infinite loops. In case of the error that you have written, there is an infinite loop, which will cause system resources to drop sharply, which is easy to cause crash. If you don't have a backup of this work, it's really desirable to cry. 3 Set a breakpoint at the loop completion, which can control the entrance and exit to see if the loop is working properly, and can quickly determine the correctness of the loop statement.

4 Set breakpoints before judging the statement, the main purpose of this breakpoint is to observe the value in the Add Watch at this time. The value of each judgment parameter at this time can see if the program is performed according to normal steps, or a logical error occurs in the judgment statement, which is a very common breakpoint setting. 9. Set various usages for Procedure and Function. Don't underestimate the three words, we usually use in defining variables, and one of his very important purposes is set in Procedure or Function. Variable ginseng is not very common in ordinary procedure and function, but there is a very important purpose. If you want to write a function, return two values ​​because the two values ​​are derived in the same function. So I want to have two return values, but the function can only have a return value. How can I solve it? Severe ginseng is sent to the field, and change the value used in the function and the process to change the value of the inner parameters. In this case, multiple parameters can be returned in a process or function.

转载请注明原文地址:https://www.9cbs.com/read-26997.html

New Post(0)