Tip Access violation at address solutions

Source: Internet
Author: User
Tags pack versions

Workaround:

Right click on "My Computer". Click Properties.


in System Properties, click Advanced.


in performance, click Settings.


in Performance options, click Data Execution Protection.


click "Add". Select the program you want to run.


OK. It's as simple as that.





Access violation (illegal access) error resolution





Access violation (illegal access), General Protection Fault (generally protective error) or invalid page Fault (Invalid page fault), although the argument is different, it is inherently always caused by the same error. Access violation is often encountered when a program that is run by a computer user attempts to access a store that is not specified for use.


Access violation at address < hexadecimal value >


in module < application name >


Read of Address < hexadecimal value >


Windows users may often see similar error prompts: "Error:access violation at address 836556f8 (004096DA). Read of Address 836556f8 (00401000) ". As a Delphi program developer, there is more chance of encountering this error than other users (^_^).


Once Windows writes data outside of the storage it is assigned to, it overwrites other programs or even the operating system's commands or data. Once this happens, the operating system will be paralyzed or shut down in some way, and you must restart your computer. For example, when the next program in Windows nt/2000 encounters this error, Dr. Watson appears and stops the program, captures some quick details, and then records them in textual form. Access violation is one of the errors encountered by some of the most annoying Windows programs. The purpose of this article is to find the solution to violation access in Delphi. The first thing to declare is that access violation has nothing to do with Microsoft Access.





with Delphi Development program, we can encounter access violation divided into two major categories: the runtime and design period.





One, design-time access violation





1. Hardware Reason


access Violation in the design period when you start or close the Delphi IDE and compile a Delphi project. Access violation information in your computer's run may be caused by a variety of reasons, including the system BIOS, the operating system, or the hardware driver, and some sound cards, video cards, and network adapters can actually cause this error. Why do you say that? Every card in the computer has its device driver. For different manufacturers, different versions of Windows, or different versions of Delphi, you may experience different problems. The next few 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 cause some odd graphics drivers to stabilize.





3. If you are using a dual-processor motherboard, you are guaranteed the same steps for modifying each processor.





4. For all hardware on your computer, use the latest driver.





2. Software reason


Although Windows is the most popular operating system on Intel's computers, due to the inherent vulnerabilities and bugs of Windows systems, the misuse of an application can cause the operating system to become quickly paralyzed (and sometimes the operating system itself can be inexplicably paralyzed). Choosing a more stable program development environment is a solution, and the following steps can help you prevent certain access violation from occurring:





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





(2) ensures that the latest service pack is already installed for Windows nt/2000. Each time you install a new service pack, you will find that the machine becomes stable.





(3) Install the current update or patch (BDE, ADO ...) for the various versions of Delphi you use. ), this is a good way to prevent mistakes in advance. Try to use the latest Delphi patch--access violation The number of errors, especially in the design period, will be greatly reduced.





(4) If you often randomly encounter access violation errors in the IDE, it is likely that you have installed a bad control, package, or wizard that is not written or compiled by the version of Delphi that you are using. Try to uninstall a custom control (or package) until the problem is resolved, and then contact the control vendor to focus on the result of the problem.





(5) Check the computer for any useless things and procedural conflicts. Strange software programs and beta products often cause access to violation errors.





(6) If the system settings are incorrect, access violation errors may also occur frequently. If you keep encountering an access violation with the same error message, record the details, and then notify the software manufacturer that may be causing the error.


These are all my suggestions for design-time access violation errors.

Two, the runtime of access violation


What are the common Run-time access violation errors in Delphi? How to prevent?





any software development will encounter situations where you write a program and test it and then send it everywhere, and the user tells you it failed.





you might consider compiling your program with the compile instruction {$D}--delphi can create a mirrored file that helps locate source code for access violation errors. Project Options dialog box (project| options| Linker & Compiler) lets you specify everything you need. For the unit file, the debug information and the unit's object code are recorded together in the units file. When compiling a program that uses this unit, the debug information increases the size of the unit file and adds additional memory overhead, but it does not affect the size and speed of the final executable file. Contains debug information and mirrored files (project| options| Linker) option will complete the line information only under {$D +} compilation directives.





Access violation usually only show up in one aspect of the program. When the problem first occurs, it is important to consider what the user is doing, and then look for a breakthrough here. From the user's point of view, your program stops their work, and they tell you that the problem appears to have delayed you. However, interacting with users is the only effective way to discover problems and improve programs.





Now you'll know how to easily find the exact path, source code files, and rows where access violation errors occur when you only give you conflicting addresses:


"Search-find Error ...".





when a run-time access violation appears, your users get error messages similar to the following:


Access violation at address < hexadecimal value >


in module < application name >


Read of Address < hexadecimal value >





If your program contains debug information compilation in the Delphi IDE, you can navigate to the line that caused the error source code.


in the Delphi program, one of the most common causes of access violation errors is the use of an object that has not been created. If the second address < hexadecimal value > is FFFFFFF or 0000000, is that how you visit? An object that has not been built. For example, you call an event for a form, but the form is not created automatically, and there is no code instantiation.





procedure Tfrmain.oncreate (sender:tobject);


var badform:tbadform;


begin


//The access violation will be generated here


Badform.refresh;


end;





assumes that Badform is in the Project Options Available Forms window List-This window is created and released manually. Invoking the Refresh method of the Badform window in the above code can cause access to violation.





If you make "Stop on Delphi Exceptions" effective on the Debugger option window, the following message pops up:


the message states the eaccessviolation has occurred. The eaccessviolation is the exception class for invalid memory access errors.





This is the information you will see when you design the program, the next message box will appear, and then the program fails:


Access violation at address 0043f193


in module ' Project1.exe '


Read of Address 000000.





the first hexadecimal number 0043f193 is the address of the Run-time error of the compiled code (Project1.exe) that occurred in access violation. Select menu item in IDE "search| Find error ... ", in the dialog box, enter the address of the error (0043f193) and then click the" OK "button. Delphi will recompile your engineering files, and then display the line of code that has a run-time error, this is the Badform.refresh line.





the most common causes of access violation errors in the Delphi environment are listed below. This list is not and cannot overwrite all possible access violation. Please send your access violation information on the forums, and you can try to solve the problem together-real examples are generally more obscure than listed errors.





1. Call an object that does not exist


as mentioned above, most access violation is justified by using objects that have not been created or have been freed. To prevent the occurrence of this type of access violation, make sure that any objects you access are first created. For example, when a table is positioned in a data module that has not been created (removed from the Auto-crete window), you may open the table in the OnCreate event of the form.





in the following code, an access violation appears after calling a deleted object (B:tbitmap) event:


var B:tbitmap;


begin


b:=tbitmap.create;


Try


//Perform some operations on B objects


finally


B.free;


end;


...


Because B has been freed, an access violation error will appear


b.canvas.textout (0,0, ' This is an Access violation ');


end;





2. No API parameters exist


If you try to pass a nonexistent parameter to the WIN API function, an access violation error will occur. The best way to resolve this type of access violation error is to look up the win API help to see the parameter information and parameter types for this API function call. For example, it is always guaranteed not to pass an invalid pointer to a buffer parameter.





3. Let Delphi release


when an object has another object, let it do the deletion work for you. Because by default, all forms (automatically created) belong to the Application object. When an application ends, it frees the Application object and releases all forms. For example, if you automatically create two forms (Form1/unit1 and Form2/unit2) at the beginning of your program, the following code causes access to violation errors:


unit Unit1;


...


uses unit2;


...


procedure Tform1.call_form2


begin


Form2.showmodal;


Form2.free;


//access violation error will occur


Form2.showmodal;


end;





4. Kill the Abnormal


Never break a temporary exception object (E), and handling an exception automatically frees the exception object. If you manually free the exception object and the program tries to release it again, an access violation error occurs:


zero:=0;


Try


dummy:= 10/zero;


except


on E:ezerodivide do


Messagedlg (' Can't divide with 0! ', mterror, [Mbok], 0);


E.free. Access violation error will appear


end;





5. Retrieves an empty string


an empty string is without any data. That is, retrieving an empty string is equivalent to accessing a nonexistent object, which results in Access violation errors:


var s:string;


begin


s:= ';


s[1]:= ' a ';


//access violation error will occur


end;





6. Direct reference Pointer


You must refer indirectly to the pointer, otherwise you will change the pointer address and may damage other storage units:


procedure Tform1.button1click (sender:tobject);


var


P1:pointer;


P2:pointer;


begin


Getmem (P1, 128);


Getmem (P2, 128);


The next line causes access violation error


Move (P1, p2, 128);


//Next line method is correct


Move (p1^, p2^, 128);


Freemem (P1, 128);


Freemem (P2, 128);


end;


These are all my suggestions for run-time access violation errors, and I hope you can also make some comments about access violation errors that are occurring in your program.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.