Windows users may often see similar to error tips: "Error: Access Vioc8. Read of Address 836556F8". As a Delphi program developer, the chance to encounter such a mistake is more (^ _ ^) than other users.
What is "Access Violation"? How to avoid its appearance during the design period?
Access Viology, General Protection Fault (General Protection Error) or Invalid Page Fault (invalid page error), although it is different, it is always caused by the same error. Access Violation is often encountered when the program runs on computer users attempts to access stores that are not specified. Access Violation At Address
Once Windows wants to write data information outside of the storage area it is assigned, it will overwrite the commands or data of other programs or even operating the system. Once this happens, the operating system will be paralyzed or closed in some form, you must restart your computer. For example, when this error is encountered in Windows NT / 2000, Dr. Watson appears and stops the program, captures some fast detail status, and then records them in text. Access Violation is one of the most annoying Windows programs. The purpose of this article is to let you find the solution to Access Viocation in Delphi. First, declare that Access Violation and Microsoft Access have no relationship.
When using the Delphi development program, we can divide the Access Violation into two categories: running period and design.
First, the design period Access Violation
1. Hardware reasons are prone to the ACCESS VIOLATION that is easily designed during starting or closing Delphi IDE and compiling a Delphi project. Access Viological information in your computer can be caused by a wide variety of reasons, including system BIOS, operating system or hardware drive lines, some sound cards, graphics cards, and network cards actually cause this error. Why do you say that? Each card in the computer has its device driver. Different issues may encounter different issues for different manufacturers, different versions of Windows or Delphi. Several steps may help you solve these problems:
1. Follow the necessary steps to confirm that there is no conflict between the drivers you install.
2. Sometimes it is possible to reduce the display resolution to stabilize some quirky graphics drivers.
3. If you use the dual processor's motherboard, you guarantee that the modification step of each processor is guaranteed.
4. Use all hardware on your computer to use the latest drivers.
2. Software Cause Although Windows in Intel's computer is the most popular operating system, due to the natural vulnerability and bugs of the Windows system, the misstaded operation of the application can cause the operating system to be rapidly paralyzed (sometimes the operating system itself will inemold) . Choosing a more stable program development environment is a solution, as follows, you can help you prevent some Access Viocation from happening:
(1) Although Windows 9X is quite popular, Windows NT / 2000 is still proven to be a stable environment, which is almost like this for all Windows code platforms.
(2) Make sure the latest Service Pack has been installed for Windows NT / 2000. Every time you install the new version of Service Pack, you will find that the machine becomes stable. (3) Pack the current update or patch (BDE, ADO ...) for the various versions of you, which is a good way to prevent mistakes in advance. Try to use the latest Delphi patch - Access Viological error, especially the number of errors in the design period will be greatly reduced.
(4) If you often have an Access Viological error in the IDE, it is very likely that you have a bad control, package, or a wizard, it is not writing or compiled by the version of Delphi you use. Try a unloading control (or package) until the problem is resolved, then contact the control vendor to pay attention to the results of this issue.
(5) Check if there is anything and procedures conflicts in your computer. The strange software programs and beta products often lead to Access Viological errors.
(6) If the system is set to have an error, the Access Viological error may also occur frequently. If you don't stop encounter an error message, record these details, then notify the software manufacturer that can cause this error.
This is all the recommendations of the ACCESS VIOLATION error.
Second, what is the common runtime for running scheme DELPHI for running period ACCESS VIOLATION? How to prevent?
Any software development will encounter such a situation: you write the program and test it, then send it everywhere, and the user tells you that it failed.
You may consider compiling your programs with compilation instructions. Engineering Options dialog (Project | Options | Linker & Compiler) Let you specify everything you need. For unit files, debug information, and unit's object code recorded together in a Unit file. When compiling programs for this unit, Debug information adds to the size of the unit file and increases additional memory overhead, but it does not affect the size and running speed of the final executable file. The products containing Debug information and mirror files (Project | Options | Linker) options are only completed under {$ D } compile instructions.
Access Viocation is usually only exhibited in a certain aspect of the program. When the problem first appears, consider what the user has operation is important, then look for breakthroughs from here. From the user's point of view, your program has stopped their work, and they tell you that the problems appear seem to let you extend this problem. However, communication with user is the only effective way you find problems and improve procedures.
Now you will be able to know how to easily discover accurate paths, source code files in the case of just giving you conflict addresses: "Search - Find Error ...".
When a running period Access Violation occurs, your user's error message is similar to the following: Access Violation At Address
If your program contains Debug information in Delphi IDE, you can locate this line that caused this error source code. In the Delphi program, the reason why the Access Viological error is the use of an object that is not created. If the second address
Assuming that Badform is in the project option "Available Forms" window list - this window is manually created and released. The refresh method that calls the BadForm window in the code will result in Access Viology.
If you take the "Stop On Delphi Exceptions" in the debugger option window, then the following information will pop up: The Message State That The Eaccessviolation Has Occurred. The Eaccessviolaion Is The Exception Class for Invalid Memory Access Errors.
This is the information you will see when you design the program. The next message will appear, then the program fails: Access Violation at address 0043f193in module 'Project1.exe'Read of Address 000000.
The first hexadecimal number 0043f193 is an address error address of the process1.exe of Access Violation. Select the menu item "Search | Find Error ..." in the IDE. Enter the error occurred in the dialog box (0043f193) and click the "OK" button. Delphi will recompile your project file, then display the line of code that occurs when the running period is wrong, here is the BadForm.refresh this line.
Most of the common causes of Access Viological errors will be listed below. This list is not the case where it is impossible to overwrite the possible Access Viocation. Please send your Access Violation information on the forum. You can try to solve this problem - the real practical case is generally much more concealed than listed.
1. Call a non-existent object As mentioned above, most of the ACCESS VIOLATION is the use of objects that are not created or already released. To prevent this type of Access Violation, make sure that any object you have access is first created. For example, when a table is positioned in a Data Module that is not created (removed from the Auto-Crete window), you may open this table in the form's oncreate event.
In the following code, after calling an object (B: Tbitmap) event that has been deleted, an Access Violation appears: var B: Tbitmap; beginb: = tbitmap.create; try // object to B Some operations finallyb.free; end; ... // Since B has been released, an Access Violation error will appear B.canvas.Textout (0, 'This is an Access Violation'); END;
2. API parameters do not exist If you try to deliver a non-existent parameter to the Win API function, an Access Viological error will appear. The best way to resolve such Access Viological errors is to check the WIN API help, see the parameter information and parameter types called this API function call. For example, it always guarantees that no buffer parameters are transmitted to an invalid pointer. 3. Let Delphi release when an object has another object, let it delete you. Because of the default, all forms (automatically created) belong to the Application object. When an application ends, it releases the Application object, and all forms are released. For example, if you automatically create two forms (Form1 / Unit1 and Form2 / Unit2) at the beginning of the program, the following code will result in Access Viological errors: Unit Unit1; ... Uses unit2; ... Procedure TFORM1.CALL_FORM2BEGINFORM2.SHOWMODAL; FORM2.FREE; // Access Viocation error will appear form2.showmodal; end;
4. Kill anomalies never destroy the temporary abnormal object (E), handle an exception automatically releases the abnormal object. If you manually release the abnormal object, the program will try to release it again, then Access Violation error: ZERO: = 0; trydummy: = 10 / zero; Excepton E: EZERODIVIDE DOMESSAGEDLG ('Can't use 0 to do addition!' , mTerror, [Mbok], 0); E.free. Access Viocation error will appear;
5. Retrieve an empty string an empty string is no data. That is to say, retrieving an empty string is equivalent to accessing a non-existing object, which will cause an Access Violation error: var s: string; begins: = '; s [1]: =' a '; // access Viocation error End will appear;
6. Direct reference pointer you must indirectly reference the pointer, otherwise you will change the pointer address and may damage other storage units: Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Varp1: POINTER; P2: POINTER; BegingeTMem (P1, 128); GetMem (P2, 128); // The next line leads to Access Violation Error Move (P1, P2, 128); // Next line method correct Move (P1 ^, P2 ^, 128); FreeMem (P1, 128); Freemem P2, 128); END; these is all the recommendations for the runtime Access Violation error, I hope that you can also make some views on the Access Violation error of your program.