How to solve access violation at address prompt when running the program

Source: Internet
Author: User

How to solve access violation at address prompt when running the program
When I open the EXE program prompt, the prompt is: access violation at address xxxxxxxxx is followed by a lot. How can this problem be solved? Baidu is a bit simple.
The solution is now published:
Right-click my computer ". Click properties ".
Click Advanced in system properties ".
Click set in performance ".
In performance options, click data protection ".
Click Add ". Select the program to run.
OK. That's simple.

How to solve Access Violation errors

Access Violation (unauthorized Access), General Protection Fault (General protective error), or Invalid Page Fault (Invalid Page error). Although they are different, they are always caused by the same error. Access Violation is often encountered when a program running by a computer user attempts to Access an unspecified bucket.
Access violation at address In module <Application name>
Read of address Windows users may often see errors similar to the following: "Error: Access violation at address 836556F8 (004096da). Read of address 836556F8 (00401000 )". As a Delphi program developer, there are more opportunities for such errors than other users (pai_^ ).
Once Windows writes data information outside the allocated storage area, it overwrites commands or data of other programs or even operating systems. Once this happens, the operating system will be paralyzed or shut down in some form. You must restart the computer. For example, when the next program in Windows NT/2000 encounters this error. watson appeared and stopped the program, captured some fast details, and recorded them in text format. Access Violation is one of the most annoying Windows program errors. The purpose of this article is to help you find a solution to Access Violation in Delphi. First, declare that Access Violation has nothing to do with Microsoft Access.

When developing programs using Delphi, we can divide Access Violation into two categories: runtime and design.

1. Access Violation during the design period

1. Hardware reasons
Access Violation during the design period may occur when you start or stop Delphi IDE and compile a Delphi project. The Access Violation information displayed on your computer may be caused by various reasons, including the system BIOS, operating system, or hardware driver line, some sound cards, video cards, and NICs may actually cause such errors. Why? Each card in a computer has its device driver. Different manufacturers, different versions of Windows, or different versions of Delphi may encounter different problems. The following steps may help you solve these problems:

1. Follow the necessary steps to verify that there is no conflict between the drivers you have installed.

2. Sometimes lowering the display resolution may make some weird graphics driver stable.

3. If you use a dual-processor motherboard, make sure that the modification steps for each processor are the same.

4. Use the latest driver for all hardware on the computer.

2. Software reasons
Although Windows is the most popular operating system on Intel computers, due to inherent Windows vulnerabilities and bugs, misoperations of applications may result in the rapid paralysis of the Operating System (sometimes the operating system itself will be inexplicably paralyzed ). Selecting a more stable development environment is the solution. The following steps can help you prevent Access Violation:

(1) Despite the popularity of Windows 9X, Windows NT/2000 has been proven to be a much more stable environment in many aspects, almost all Windows code platforms.

(2) ensure that the latest service pack is installed for Windows NT/2000. After installing the new service pack, you will find that the machine becomes stable.

(3) install the Current updates or patches (BDE, ADO…) for your various versions of Delphi ......), This is a good way to prevent errors in advance. Try to use the latest Delphi patch-the number of Access Violation errors, especially the number of errors during the design period, will be greatly reduced.

(4) If you often encounter Access Violation errors randomly in IDE, it is likely that you have installed a bad control, package, or wizard, it is not written or compiled by the Delphi version you are using. Try to uninstall the custom control (or package) one by one until the problem is solved, and then contact the control vendor to follow up the problem.

(5) Check whether something useless in the computer conflicts with the program. Strange software programs and beta products often cause Access Violation errors.

(6) If the system is set incorrectly, Access Violation errors may also occur frequently. If you constantly encounter an Access Violation with the same error message, record these details and notify the software manufacturer that may cause this error.
These are all my suggestions for Access Violation errors during the design period.

2. Access Violation during runtime
What are common Access Violation errors in Delphi during runtime? How to prevent it?

Any software development may encounter such a situation: you write the program and test it, and then send it everywhere. The user tells you that it has failed.

You may consider using the compilation command {$ D} to compile your program -- Delphi can create an image file that helps locate the source code of Access Violation errors. The Project | Options | Linker & Compiler dialog box allows you to specify everything you need. For the unit file, the debug information and the unit object code are recorded in the unit file together. When compiling a program that uses this unit, the debug information increases the size of the unit file and increases the memory overhead, but it does not affect the size and running speed of the final executable file. A product that contains the debug information and the image file (Project | Options | Linker) option can complete the line of information only under the {$ D ++} compilation command.

Access violation is usually manifested only in one aspect of the program. When a problem occurs for the first time, it is very important to consider what operations the user has performed, and then find a breakthrough here. From the user's point of view, your program has terminated their work, and they will tell you that the problem seems to have delayed you to solve the problem. However, communicating with users is the only effective way for you to discover problems and improve your programs.

Now you can know how to easily find accurate paths, source code files, and Access violation errors when only conflicting addresses are given to you:
"Search-Find Error ...".

When an Access violation occurs during the runtime, the error message you get is similar to the following:
Access violation at address In module <Application name>
Read of address
If your program contains debug information compilation in Delphi IDE, you can locate the line that causes this error source code.
In the Delphi Program, the most common cause of Access Violation error is that an uncreated object is used. If the second address
? Procedure TfrMain. OnCreate (Sender: TObject );
Var BadForm: TBadForm;
Begin
// Access violation will be generated here
BadForm. Refresh;
End;

Assume that BadForm is in the "Available Forms" window list of the project option-this window needs to be created and released manually. In the above Code, calling the Refresh method of the BadForm window will lead to Access violation.

If you enable "Stop on Delphi Exceptions" in the Debugger option window, the following information will pop up:
The message states that the EAccessViolation has occurred. The EAccessViolation is the exception class for invalid memory access errors.

This is the information you will see when designing the program. The next information box will appear, and the program will fail:
Access violation at address 0043F193
In module 'Project1.exe'
Read of address 000000.

The first hexadecimal number 0043F193 is the address of the Access violationcompilation code (project1.exe) during the runtime error. In IDE, select the menu item "Search | Find Error ...", Enter the error address (0043F193) in the dialog box and click "OK. Delphi will recompile your project file and display the line of code that has encountered a runtime error. Here is the line BadForm. Refresh.

The following lists most common causes of Access violation errors in the Delphi environment. This list does not and cannot cover all possible Access violation situations. Please send your Access violation information on the Forum. You can try to solve this problem together-the actual case is generally much more obscure than the listed errors.

1. Call a nonexistent object
As mentioned above, the reason for most Access violation is that an object is not created or released. To prevent this type of Access violation, make sure that any object you Access is created first. For example, if a Table is located in an uncreated data module (removed from the auto-crete window), you may open the Table in the OnCreate event of the form.

In the following code, after calling a deleted object (B: TBitmap) event, an Access violation occurs:
Var B: TBitmap;
Begin
B: = TBitmap. Create;
Try
// Perform some operations on object B
Finally
B. free;
End;
...
// Because B has been released, an Access violation error will occur.
B. Canvas. TextOut (0, 0, 'This is an Access Violation ');
End;

2. nonexistent API Parameters
If you try to pass a non-existent parameter to the Win API function, an Access violation error will occur. The best way to solve this Access violation error is to check the Win API help to see the parameter information and parameter type of this API function call. For example, always do not pass an invalid pointer to a buffer parameter.

3. Release Delphi
When an object has another object, let it delete it for you. By default, all forms (automatically created) belong to the Application object. When an Application ends, it releases the Application object and releases all forms. For example, if you automatically create two forms (Form1/Unit1 and Form2/Unit2) at the beginning of the program, the following code will cause Access violation errors:
Unit Unit1;
...
Uses unit2;
...
Procedure TForm1.Call _ Form2
Begin
Form2.ShowModal;
Form2.Free;
// Access violation error will appear
Form2.ShowModal;
End;

4. Killing an exception
Never destroy the temporary exception object (E). When an exception is handled, the exception object is automatically released. If you manually release the exception object, the program will try to release it again, and the Access violation error will occur:
Zero: = 0;
Try
Dummy: = 10/Zero;
Except
On E: EZeroDivide do
MessageDlg ('Do not use 0 as the divisor! ', MtError, [mbOK], 0 );
E. free. // Access violation error will appear
End;

5. Retrieve an empty string
A Null String does not have any data. That is to say, retrieving an empty string is equivalent to accessing a non-existent object, which will lead to an Access violation error:
Var s: string;
Begin
S: = '';
S [1]: = 'a ';
// Access violation error will appear
End;

6. Direct Pointer Reference
You must indirectly reference the pointer. Otherwise, you will change the pointer address and possibly destroy other storage units:
Procedure TForm1.Button1Click (Sender: TObject );
Var
P1: pointer;
P2: pointer;
Begin
GetMem (p1, 128 );
GetMem (p2, 128 );
// Access violation error caused by the next row
Move (p1, p2, 128 );
// The method for the next row is correct
Move (p1 ^, p2 ^, 128 );
FreeMem (p1, 128 );
FreeMem (p2, 128 );
End;
These are all my suggestions on Access Violation errors during runtime. I hope you can also put forward some comments on Access Violation errors in your program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.