2014-04-12 4 views
0

ComboBox4, ComboBox1 및 Button5가 있습니다 Button5를 클릭하면 프로그램이 ComboBox4 및 ComboBox1 구성 요소 목록에서 combobox4에서 선택한 구성 요소를 제거해야합니다. 하지만 콤보 상자에서 선택한 구성 요소 제거

procedure TForm1.Button5Click(Sender: TObject); 
var 
cat : Integer; 
trinti: TComponent; 
catT : String; 
begin 
catT := ComboBox4.Text; 
cat := ComboBox4.Items.IndexOf(catT); 
trinti := ComboBox4.Components[cat]; 

ComboBox1.Items.BeginUpdate; 
ComboBox4.Items.BeginUpdate; 
    ComboBox4.RemoveComponent(trinti); 
    ComboBox1.RemoveComponent(trinti); 
ComboBox1.Items.EndUpdate; 
ComboBox4.Items.EndUpdate; 

removeCat(catT); 
end; 

답변

2

:(Components 속성을 도와주세요 ... 다음 코드로 경계 오류에서 목록을, 그리고 RemoveComponent 방법은 여기에 사용하는 잘못된 일이다.이 소유위한 것입니다 일반적으로 아무것도 소유하지 않는 양식의 유일한 것은 양식이므로 콤보 상자에 Components을 사용하면 항상 오류가 발생합니다.

대신 콤보 상자의 Items 속성을 사용해야하며, 및 해당 Delete 방법. 다음과 같이 보일 수 있습니다.

var 
    Index: Integer; 
.... 
catT := ComboBox4.Text; 
Index := ComboBox4.Items.IndexOf(catT); 
if Index <> -1 then 
    ComboBox4.Items.Delete(Index); 
+0

이렇게 : ComboBox4.Items [cat] .Delete ;? 그러나 Items []에는 삭제 방법이 없습니다. :/ – user1804119

+1

아니요. 내 대답의 코드 샘플과 같습니다. –

+0

알 겠어,하지만 여전히리스트가 어딘가에있다. 내 코드를 보아라. http://pastebin.com/ruNcU4yf – user1804119

관련 문제