Re: [問題] 自訂函數的參數有控制項

看板C_and_CPP (C/C++)作者 (~ ~ ~)時間14年前 (2011/09/29 20:46), 編輯推噓2(205)
留言7則, 2人參與, 最新討論串2/3 (看更多)
還好還記得 XD 在 .h 有宣告的元件 (也就是用拉的) TListBox *ListBox1; 可以在 .cpp 的 Form1 直接用 (也就是不用傳入參數) 因為 ListBox1 是那個類別裡的東西. 找一個 button 去加一些資料到 ListBox1, 就像這樣寫: void __fastcall TForm1::Button1Click(TObject *Sender) { ListBox1->Items->Add("Chad"); ListBox1->Items->Add("Equatorial Guinea"); ListBox1->Items->Add("Egypt"); ListBox1->Items->Add("Madagascar"); ListBox1->ItemIndex = ListBox1->Items->Count-1; } 另外, 自己去 new 的 TListBox, 就要這麼寫 (綁在另一個button上): void __fastcall TForm1::Button2Click(TObject *Sender) { TListBox *ListBox2 = new TListBox(Sender); ListBox2->Parent = Form1; // 其他的屬性(Left/Top/...)自己再加上去 } 試出來可以用. 但不知有沒有side-effect. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.176.153

09/29 20:48, , 1F

09/29 20:48, , 2F
lesson for BCB ListBox.
09/29 20:48, 2F

09/29 20:50, , 3F
我就是嫌寫在button太長,想用function把他包住啊...XD
09/29 20:50, 3F

09/29 20:50, , 4F
這樣看起來比較簡潔易懂
09/29 20:50, 4F

09/29 21:02, , 5F
你要怎麼用你再改吧. 我只是提供線索.
09/29 21:02, 5F

09/29 21:03, , 6F
也沒人規定button就要直接用到listbox.
09/29 21:03, 6F

09/29 22:00, , 7F
搞笑了,其實只要include <vcl>即可@@
09/29 22:00, 7F
文章代碼(AID): #1EX6Y83- (C_and_CPP)
文章代碼(AID): #1EX6Y83- (C_and_CPP)