Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Violation

Status
Not open for further replies.

Keeganscurlyperm

Programmer
Feb 15, 2002
2
GB
From: Reasonably new user of Delphi

Under what circumstances would I get an 'access violation' message during the running of my Delphi program?

 
Attempting to access something that has not been created. Or trying to free/access something that has already been freed.

lou
 
For example:
Code:
var mystrings: TStringList;
begin
  mystrings.Add('bad');  // this will cause an AV

  mystrings := TStringList.Create;
  mystrings.Add('good');  // this is OK

  ShowMessage(mystrings[5]);  // this will cause a list index out of bounds

  mystrings.Free;

  mystrings.Add('also bad);  //  this will also cause an AV
end;
-- Doug Burbidge mailto:doug@ultrazone.com
 
Also, trying to close a form that still has enabled Timers
will cause an EAccessViolation ... [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
I can see that if you read this from the help:--
"
EAccessViolation is raised when an application

• Dereferences a nil pointer.
• Writes to a code page.
• Attempts to access a memory address for which there is no virtual memory allocated to the application.
"
you might be confused.
There are probobly lots of other ways to get an AV as well as the previous answers, Look at error trapping with Try/Except Try/Finally constructs though in my experiance these won't always work with AV's and the debugger may miss the actual cause/line of the error.
Weez gave the best generalisation I think.
What is happening is that the Delphi compiler is trying to stop you sticking things where you shouldnt in the memory. Unlike a lot of 'C' compilers which will let you write all over it.
You will learn all the ways this can happen (and how to avoid it) only with experiance.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top