473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Access violation with AnsiStrings

I'm working with C++ Builder 5.0 Enterprise Edition, and I got this
message:

Project CntSch.exe raised exception class EAccessViolation with message
'Access violation at address 40004B66 in module VCL50.BPL...

____________________

My code is this:

// I define some types:

typedef AnsiString tipoEsquema;

struct tnodo {
tipoEsquema squema;
int cntEsq;
struct tnodo *siguiente;
};

typedef struct tnodo tipoNodo;

-----
// Then I try to use them in a code segment:

tipoEsquema *estosEsq =
(tipoEsquema*)malloc(cuantosEsq*sizeof(tipoEsquema ));

lonCad = someConstant;
for (i = 0; i < cuantosEsq; i++)

// *** I got the message error in next line

estosEsq[i] = AnsiString::StringOfChar('0',lonCad);

-----
/*
I commented the part of the code that calls that, and later in code, I try
this function:
*/

tipoNodo* creaNodo(tipoNodo *valor)
{
tipoNodo *nnodo = (tipoNodo *)malloc(sizeof(tipoNodo));

if (nnodo != NULL) {

// **** I got that error back here

nnodo->squema = valor->squema;
nnodo->cntEsq = valor->cntEsq;
nnodo->siguiente = NULL;
}

return nnodo;
}

----

I will appreciate any help.

Thanks

Paul RC
Jul 22 '05 #1
3 4309

"paulrc_25" <pa**@cimat.mx> wrote in message
news:2b******************************@localhost.ta lkaboutprogramming.com...
I'm working with C++ Builder 5.0 Enterprise Edition, and I got this
message:

Project CntSch.exe raised exception class EAccessViolation with message
'Access violation at address 40004B66 in module VCL50.BPL...

____________________

My code is this:

// I define some types:

typedef AnsiString tipoEsquema;

struct tnodo {
tipoEsquema squema;
int cntEsq;
struct tnodo *siguiente;
};

typedef struct tnodo tipoNodo;

-----
// Then I try to use them in a code segment:

tipoEsquema *estosEsq =
(tipoEsquema*)malloc(cuantosEsq*sizeof(tipoEsquema ));


This is wrong, try this

tipoEsquema *estosEsq = new tipoEsquema[cuantosEsq];

Don't use malloc, free or realloc in a C++ program. There don't work on
classes like AnsiString. Use new and delete instead. Or use a vector.

john
Jul 22 '05 #2
"paulrc_25" <pa**@cimat.mx> wrote in message news:2b******************************@localhost.ta lkaboutprogramming.com...
I'm working with C++ Builder 5.0 Enterprise Edition, and I got this
message:

Project CntSch.exe raised exception class EAccessViolation with message
'Access violation at address 40004B66 in module VCL50.BPL...

____________________

My code is this:

// I define some types:

typedef AnsiString tipoEsquema;

struct tnodo {
tipoEsquema squema;
int cntEsq;
struct tnodo *siguiente;
};

typedef struct tnodo tipoNodo;

-----
// Then I try to use them in a code segment:

tipoEsquema *estosEsq =
(tipoEsquema*)malloc(cuantosEsq*sizeof(tipoEsquema ));

lonCad = someConstant;
for (i = 0; i < cuantosEsq; i++)

// *** I got the message error in next line

estosEsq[i] = AnsiString::StringOfChar('0',lonCad);
You have made the mistake of using operator= upon an
object that was never properly constructed. Your use
of malloc is the most direct problem here. The problem
goes deeper, however. You need to learn fundamental
C++ before using C++ classes, such as AnsiString.

Here is the order of steps I would recommend:
1. Learn what C++ constructors and destructors are for.
2. Learn what operator= is for a class and how it differs
from the copy constructor.
3. Begin to use already-defined (in a library) C++ classes.

To cure the immediate problem, you could get closer
by using this:
tipoEsquema *estosEsq = new topoEsquema[cuantosEsq];
instead of your malloc call.
-----
/*
I commented the part of the code that calls that, and later in code, I try
this function:
*/

tipoNodo* creaNodo(tipoNodo *valor)
{
tipoNodo *nnodo = (tipoNodo *)malloc(sizeof(tipoNodo));

if (nnodo != NULL) {

// **** I got that error back here

nnodo->squema = valor->squema;
nnodo->cntEsq = valor->cntEsq;
nnodo->siguiente = NULL;
}

return nnodo;
}

----

I will appreciate any help.

Thanks
Good luck. You will need plenty of it if you plow into
C++ usage without learning the fundamentals first.
Paul RC

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 22 '05 #3
Larry Brasfield wrote:
You have made the mistake of using operator= upon an
object that was never properly constructed. Your use
of malloc is the most direct problem here. The problem
goes deeper, however. You need to learn fundamental
C++ before using C++ classes, such as AnsiString.

Actually, the reverse is true. He should learn fundamental
C++ classes before dealing with advanced concepts like
malloc().

There needs to be some C unlearning before doing anything
in C++.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steven Reddie | last post by:
I understand that access violations aren't part of the standard C++ exception handling support. On Windows, a particular MSVC compiler option enables Microsoft's Structured Exception Handling...
0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
5
by: Alex | last post by:
Hello Im working on project for my college, nevermind (but it urgent :((()... So I have this code example (in VS 6.0) in main class : REAL *Input; ....
7
by: Daniel | last post by:
I want to write a method to remove the last node of the linked list. But the error "Access Violation" exists and the error point to this method. What does it means by Access Violation and how can...
0
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a...
1
by: Thomas Albrecht | last post by:
My application fails during initialization of the dlls with an ExecutionEngineException and a access violation in the MFC app. The structure of the program looks like: MFC app -> mixed DLL ->...
2
by: Boris Fortes | last post by:
I need to unhook event receiver as result of native C++ event. It unhooks successfully, but __raise does not return and throws access violation. Visual Studio 2003 How to reproduce: Consol...
2
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.