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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Violation / Write of Access error

Status
Not open for further replies.

crzydave

Technical User
Jul 18, 2002
1
US
When I attempt to run my compiled code, I get the message "Project faulted with message: 'access violation at 0x400089d1: write of access 0x00030dc8'. It happens just after I've established a form, and assigned values to the states of clickable icons on the form Element1.
Code:
__fastcall TElement1::TElement1(TComponent* Owner)
       : TForm(Owner)
{
        int index = 0;
        do {
           state[index].v_UGCtank1    = 0;
           state[index].v_UGCtank2    = 0;
           ...
           index++;
        } while (index < 30);
}
void __fastcall TElement1::v_UGCtank1_click(TObject *Sender)
{ ...
The violation appears at the v_UGCtank1_click line. I've seen similar constructs work in other programs - am I missing something? Is the problem elsewhere? Thanks...
 
Well, what is state? If it is a pointer, did you new it? Also, are you sure it is 30 in size? One more thing, if you know all these constants (i.e. state is an array of size 30) you can just do a memset

memset(state,0,sizeof(*state)); But only if all the variables are being set to zero. If this is specific to just a select amount of variables then it wont work. However, if this is something that will be called alot, it may be worth looking into a member function for the struct that you can call to reinitialize the specific variables.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top