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

ListView Access Violation

Status
Not open for further replies.

LoneRanger123

Programmer
Dec 19, 2000
62
GB
This code is used to create a Directory list. WHen I Run it and it gets to the ListItem->Caption = "hi"; (thats a test) line it gives an access violation. The code was copied from a Borland Help file Exampe and Edited (with my code); This was from TListView Add() help example. Any thoughts?

Code:
void __fastcall TSidebar::make_dir_listing(TObject *Sender)
{
    TListItem  *ListItem;
     LIST->Items->Clear();
  int i = 0;
  for (i;i < 100;i++)
  {
    if (Dir_Entries[i].Name != &quot;&quot;)
    {
        ///ListItem = LIST->Items->Add();
          //MessageDlg(Dir_Entries[i].Name.Pos(&quot;.&quot;) - 1,mtError,TMsgDlgButtons() << mbOK,0);
     //ListItem->Caption = &quot;hi&quot;;
         ListItem = LIST->Items->Add();
    ListItem->Caption = &quot;hi&quot;;

     //ListItem->ImageIndex = Dir_Entries[i].IconIndex;

    }
  }
}
 
BCB Help example is working properly.
Access Violation occures when program trys to write to
protected memory.
It's not correct:
ListItem = LIST->Items->Add();
write so:
ListItem = LIST;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top