Board index » cppbuilder » Access Violation in TListbox->Items->Strings when the Item is a verylong string

Access Violation in TListbox->Items->Strings when the Item is a verylong string

Hi,

Quote
>    int linesToGo = lstDiscussion->Count/3;
>    for (int i=0;i<linesToGo;i++) {
>        AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
>        AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
>        AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
>    }

 How many times do you define UserName, Date and Message ? Can't you just
define these Strings one time before the loop ?
AnsiString UserName, Date, Message;
for (...) {
...

Quote
}
> When I try to retreive Message the following exception occurs ONLY when
> lstDiscussion->Items->Strings[i*3+2] is a Very long (1050) chars.

Where do you retreive Message ? In the loop (warning on the scope of
Message) ?

Quote
> Acces violation at adres 000000003e. Read of adres 0000000003e.

> When lstDiscussion->Items->Strings[i*3+2] is a small string, no
> exception happens.

How do you display Message ?
 

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


Quote
kikof wrote:
>Hi,

>>   int linesToGo = lstDiscussion->Count/3;
>>   for (int i=0;i<linesToGo;i++) {
>>       AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
>>       AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
>>       AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
>>   }

> How many times do you define UserName, Date and Message ? Can't you just
>define these Strings one time before the loop ?

That is possible, but not the issue here.

- Show quoted text -

Quote
>AnsiString UserName, Date, Message;
>for (...) {
>...
>}

>>When I try to retreive Message the following exception occurs ONLY when
>>lstDiscussion->Items->Strings[i*3+2] is a Very long (1050) chars.

>Where do you retreive Message ? In the loop (warning on the scope of
>Message) ?

AnsiString Message = lstDiscussion->Items->Strings[i*3+2];

The exception occurs in this line!

Quote
>>Acces violation at adres 000000003e. Read of adres 0000000003e.

>>When lstDiscussion->Items->Strings[i*3+2] is a small string, no
>>exception happens.

>How do you display Message ?

I do nothing with it yet. The exception already occured.

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


I've tried your code and I get no error with it (9 TListBox lines filled) :

   lstDiscussion->Items->Strings[8] = AnsiString::StringOfChar('A',2000); //
enough long, isn't it ?
   int linesToGo = lstDiscussion->Items->Count/3;
   for (int i=0;i<linesToGo;i++) {
       AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
       AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
       AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
   }

You have to look for bugs in another parts of your code I think.

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


Please use the lstDiscussion->Items->Add method to add them first.

The following string gave me the error (one line!):

When you instantiate a Visual Basic component from an Active Server
Pages (ASP) page, you may receive the following error:\r\n\r\nServer
object error 'ASP 0178 : 80070005'\r\nServer.CreateObject Access
Error\r\n\r\nThe call to Server.CreateObject failed while checking
permissions. Access is denied to this object. With Visual Studio 6.0
Service Pack 5 (SP5), you may receive the following error
message:\r\n\r\nError number: -2147024891\r\n\r\nASP 0178
Server.CreateObject Access Error\r\nThe call to Server.CreateObject
failed while checking permissions. This error may occur after you
install a new Visual Basic component on your Web server using a Standard
Setup Package that was created on a computer with Microsoft Visual
Studio 6.0 SP4 or SP5.\r\n\r\nCause\r\nThe authenticated user for the
Visual Basic (VB) run-time file (Msvbvm60.dll) does not have sufficient
permissions. The authenticated user is the IUSR_ computername account
when you use anonymous access or the user that is authenticated with the
Web page.

Quote
kikof wrote:
>I've tried your code and I get no error with it (9 TListBox lines filled) :

>   lstDiscussion->Items->Strings[8] = AnsiString::StringOfChar('A',2000); //
>enough long, isn't it ?
>   int linesToGo = lstDiscussion->Items->Count/3;
>   for (int i=0;i<linesToGo;i++) {
>       AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
>       AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
>       AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
>   }

>You have to look for bugs in another parts of your code I think.

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


Please use the  lstDiscussion->Items->Add(aMessage);
method to add it first and let aMessage be the 3d item you add string.

The following string gave me the error (one line!):

When  you  instantiate  a  Visual  Basic  component  from  an  Active  Server
Pages  (ASP)  page,  you  may  receive  the  following  error:\r\n\r\nServer
object  error  'ASP  0178  :  80070005'\r\nServer.CreateObject  Access
Error\r\n\r\nThe  call  to  Server.CreateObject  failed  while  checking
permissions.  Access  is  denied  to  this  object.  With  Visual  Studio  6.0
Service  Pack  5  (SP5),  you  may  receive  the  following  error
message:\r\n\r\nError  number:  -2147024891\r\n\r\nASP  0178
Server.CreateObject  Access  Error\r\nThe  call  to  Server.CreateObject  failed
   while  checking  permissions.  This  error  may  occur  after  you  install  a
   new  Visual  Basic  component  on  your  Web  server  using  a  Standard
Setup  Package  that  was  created  on  a  computer  with  Microsoft  Visual
Studio  6.0  SP4  or  SP5.\r\n\r\nCause\r\nThe  authenticated  user  for  the
Visual  Basic  (VB)  run-time  file  (Msvbvm60.dll)  does  not  have  sufficient
   permissions.  The  authenticated  user  is  the  IUSR_  computername  account
   when  you  use  anonymous  access  or  the  user  that  is  authenticated
with  the  Web  page.

So could you please rewrite it like:

     lstDiscussion->Items->Add("test");
     lstDiscussion->Items->Add("test2");
     lstDiscussion->Items->Add("Add the very long string here!!");
     //enough long, isn't it ?
     int linesToGo = lstDiscussion->Items->Count/3;
     for (int i=0;i<linesToGo;i++) {
         AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
         AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
         AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
     }

Quote
kikof wrote:

  >I've tried your code and I get no error with it (9 TListBox lines filled) :
  >
  >   lstDiscussion->Items->Strings[8] = AnsiString::StringOfChar('A',2000); //
  >enough long, isn't it ?
  >   int linesToGo = lstDiscussion->Items->Count/3;
  >   for (int i=0;i<linesToGo;i++) {
  >       AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
  >       AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
  >       AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
  >   }
  >
  >You have to look for bugs in another parts of your code I think.
  >
  >
  >

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


I not forgot you but I haven't BCB at office.

Quote
>      lstDiscussion->Items->Add("test");
>      lstDiscussion->Items->Add("test2");
>      lstDiscussion->Items->Add(AnsiString::StringOfChar('A',2000)); // I
modified here
>      int linesToGo = lstDiscussion->Items->Count/3;
>      for (int i=0;i<linesToGo;i++) {
>          AnsiString UserName = lstDiscussion->Items->Strings[i*3+0];
>          AnsiString Date = lstDiscussion->Items->Strings[i*3+1];
>          AnsiString Message = lstDiscussion->Items->Strings[i*3+2];
>      }

And you know what ? This code run just fine.
After that, I copied/pasted your long line at the place of
AnsiString::StringOfChar('A',2000). I added \ at each end of code line in
order to make it a valid string. Again this works perfectly.
You have to believe me when i tell you there is a bug somewhere else in your
program. Just create like me an another project for testing this very thing.
An unlucky use of a pointer several lines before can do that, for sure... I
ever saw something like that in some of my programs. A bug that it was coded
several days before suddenly appears in another program part just because
the memory you take at this time is committed by the bug (a pointer story in
general).

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


Thanks for the tip, but I cannot reproduce this using a new application.
Somehow I've gotten some weird TString at that current Item, because
even the de{*word*81} and watch window hangs
when I try to get the content of that item.
The strange thing, I am now looking for, how did I get this weird string
there in the first place?
I have got not clues where to look for now. Anyhow thanks alot for all
your help.
Quote
kikof wrote:
>Hi,

>I not forgot you but I haven't BCB at office.

>And you know what ? This code run just fine.
>After that, I copied/pasted your long line at the place of
>AnsiString::StringOfChar('A',2000). I added \ at each end of code line in
>order to make it a valid string. Again this works perfectly.
>You have to believe me when i tell you there is a bug somewhere else in your
>program. Just create like me an another project for testing this very thing.
>An unlucky use of a pointer several lines before can do that, for sure... I
>ever saw something like that in some of my programs. A bug that it was coded
>several days before suddenly appears in another program part just because
>the memory you take at this time is committed by the bug (a pointer story in
>general).

Re:Access Violation in TListbox->Items->Strings when the Item is a verylong string


Hi, please check the message with the subject:
" Brain braker in TListbox->Add causes a Access Violation in 0000003e.
Please help me.... "
for a follow up. I created a new discussion so that more people can help me.

Other Threads