Jump to content
  • Advertisement
Sign in to follow this  
Q-Parser

I'm getting EAccessViolation...

This topic is 4808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm coding a school project and I've stuck with this error. I'm getting EAccessViolation when I'm trying to access Caption property of ListView in Form1 from within Form2. I don't just get it as Unit2 can "see" Form1, I mean I have the Unit1 header included in Unit2. Just a sample for illustration: Form1->ListView1->Items->Item[0]->Caption=Form2->Edit3->Text; I looked in the help what this error message means but it didn't provide me with a single clue what I have done wrong. Thanks for your help. PS: I'm using C++ Builder, if it is any help.

Share this post


Link to post
Share on other sites
Advertisement
It means that you are trying to access a piece of memory at an invalid location.
So either one (or both) of:

Form1->ListView1->Items->Item[0]->Caption
Form2->Edit3->Text;

is invalid.

Share this post


Link to post
Share on other sites
More likely the first one but I have no clue how to solve it. I don't understand why I can interact with Form2 objects from within Form1 and not vice versa :(

Share this post


Link to post
Share on other sites
Ok, I've got another one. But I can't understand this:

FILE *f;
AnsiString temp;

fopen("file.db","r");
fscanf(f, "%s",&temp);
fclose(f);


The content of file.db is just "string", nothing more.

Share this post


Link to post
Share on other sites
Quote:
Original post by j0seph
Ok, I've got another one. But I can't understand this:

FILE *f;
AnsiString temp;

fopen("file.db","r");
fscanf(f, "%s",&temp);
fclose(f);


The content of file.db is just "string", nothing more.


This one is easier: f is not initialized. fopen() returns a new FILE pointer.

FILE *f;
f = fopen("file.db","r");

Then, you need to test f (if the file is not found or cannot be opened, fopen() returns NULL)

if (f)
{
fscanf(f, "%s",&temp);
fclose(f);
}


About your first one: you may find where is your error by adding tests on each pointer:

// Form1->ListView1->Items->Item[0]->Caption
if (Form1)
{
if (Form1->ListView1)
{
.. and so on
}
}

You notice: it looks bad. OTOH, you should not gain access to Caption ths way - it is far better to encapsulate the whole thing (create a method in your form class that calls the correct method of your ListView object - I can't believe there's no method to set the Caption value of the first item).

HTH,

Share this post


Link to post
Share on other sites
Do you have form2 on autocreate?
If you have removed the form from being created automatically in the projects properties then you will get this exception.
Also does the listview actually have items in it?
You cannot access item[0] unless you have done an AddItem(String) or added items at design time.

Also when using files in CBuilder look inhelp for TFileStream
You might find that easier to use.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!