[問題] 點ListView項目 在TreeView顯示對應內容

看板C_and_CPP作者 (天鵝絨的幽闇)時間15年前 (2010/01/05 08:59), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
我是用BCB寫程式的~ 我想寫一個點擊ListView項目 然後在TreeView顯示對應內容的程式 以下是我寫的程式碼~ //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { TListItem *List1; ListView1->ViewStyle=vsReport; ListView1->Columns->Add(); ListView1->Columns->Add(); ListView1->Columns->Items[0]->Width = 50; ListView1->Columns->Items[0]->Caption="No."; ListView1->Columns->Items[1]->Width = 70; ListView1->Columns->Items[1]->Caption="Protocol"; List1 = ListView1->Items->Add(); List1->Caption = "1"; List1->SubItems->Add("1"); List1 = ListView1->Items->Add(); List1->Caption = "2"; List1->SubItems->Add("2"); } //--------------------------------------------------------------------------- void __fastcall TForm2::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected) { TreeView1->Items->Clear(); TreeView1->Items->Add(NULL, ListView1->Selected->Index); } //--------------------------------------------------------------------------- 但是執行程式之後 卻出現"Access violation at address ... in module ... Read of address ..."的錯誤訊息 請教大大們如何解決~ 感激不盡!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 120.126.10.88

01/05 19:27, , 1F
不拿debugger看一下錯在哪?
01/05 19:27, 1F
文章代碼(AID): #1BGlztOS (C_and_CPP)