2012-03-29 47 views
6

我有一個TGroupBox幾個組件裏面,我試圖將所有這些都是分組框裏面這樣爲什麼我的TGroupBox的ComponentCount屬性返回0?

for i := 0 to GroupBox1.ComponentCount -1 do 
    if (GroupBox1.Components[i]) is TWinControl then 
    TWinControl(GroupBox1.Components[i]).Enabled:=False; 

組件的Enabled財產,但ComponentCount總是返回0,有什麼我」失蹤了?

回答

14

ComponentCount屬性是檢索擁有由組件組件的數量,在所有孩子迭代控件必須使用ControlCountControls性能。

+4

要在此進一步闡述,被放置在設計時組件** **擁有由父'TForm'在運行時,這就是爲什麼他們不會出現在的了'Components'列表'TGroupBox'。它們位於'TForm'的'Components'列表中。 – 2012-03-29 01:42:05

-1
for i := 0 to GroupBox1.ControlCount - 1 do 
    if (GroupBox1.Controls[i]) is TWinControl then 
     TWinControl(GroupBox1.Controls[i]).Enabled:=False; 
+2

對代碼的解釋對於使答案有用很有幫助。 – 2012-03-29 07:01:09

+0

在stackoverflow上,Python的答案通常只是顯示代碼。對於某些問題,這實際上是一個非常簡潔和有用的表單。對於德爾福來說,我認爲這不是一個好主意,但即使是幾句話總比沒有好。 – 2012-03-29 19:52:37