TListItem->SubItems->Add throws an exception

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

TListItem->SubItems->Add throws an exception

Postby gbrandt » Thu Oct 28, 2004 12:05 pm

I have the following code in the 'OnData' method for a TListView with OwnerData:

Code: Select all
   char buffer[MAX_PATH];

      // get the data index
      unsigned long index = ListItem->Index );
      long error;

      // get the data
      const sInventoryItem &Item = gInventoryManager.RetrieveItemByIndex( index, error );

      if ( error == LOG_S_OK )
         // all is ok, fill the listitem
         ListItem->Caption = Item.RecordDate;
         ListItem->SubItems->Add( Item.Description );

         if ( Item.Format.Length() == 0 )
            ListItem->SubItems->Add( "Format String unknown" );
 *           ListItem->SubItems->Add( Item.Format );
         // convert time into time string
         LengthToWordsShort( Item.Length, buffer, MAX_PATH );
         ListItem->SubItems->Add( buffer );
         ListItem->Caption = "error in list filling";

I was getting list views with the third and fourth item missing from a detailed view. The problem would only appear after 4 or 5 days running and not all the time, so I put the code in to catch exceptions and to check for NULL strings (basically to check if I made an error or if Borland made the error). It turns out that the SubItems->Add method is throwing an error on the line marked with an *. Does anyone have any idea why this would happen. The string itself is valid ( I have other code that uses the same string to generate HTML and it comes out correctly). This means that the data is valid. The list box only has about 10,000 items in, but once the error occurs a list box with 1 item in has the same problem. Quitting and restarting the program, with the same data, fixes the issue. I am using Builder 5 with all of the patches.

Thanks Gregor


Postby 2ffat » Mon Nov 01, 2004 11:52 am

I haven't had time to go through the code is detail, but it sounds like a memory leak somewhere. Are you deleting everything you create (memory, components, etc.)?
James P. Cottingham

Look at me still talking
when there is science to do.
User avatar
Forum Mod
Forum Mod
Posts: 435
Joined: Wed Jun 23, 2004 7:07 am
Location: South Hill, VA


Postby gbrandt » Mon Nov 01, 2004 12:32 pm

CodeGuard and MemProof report no memory losses. Independent code reviews have spotted no flaws....unless I have to clear the TStringList in the TListView List Items myself?


Return to Technical

Who is online

Users browsing this forum: No registered users and 18 guests