2011-09-30 80 views
0

我在delphi 7中創建了TLabel和TCombobox的打包對象(TMyComponent)。 我創建了一個TMyComponent的動態數組(MyArray)。現在在添加按鈕上單擊我已經增加了MyArray的長度並創建了TLabel和TCombobox的對象並顯示在屏幕上。如果我添加了5個組件,我們如何獲得Myaaray的當前選定組件意味着如果我從屏幕中選擇了第三個組件,那麼我如何獲得值3作爲回報?感謝您的幫助delphi動態數組

回答

3

我認爲你正在尋找這樣的功能:

function FindMyComponentIndex(
    Selected: TMyComponent; 
    const Components: array of TMyComponent 
): Integer; 
begin 
    for Result := low(Components) to high(Components) do 
    if Components[Result]=Selected then 
     exit; 
    Result := -1; 
end; 

我相信這將是顯而易見如何調用該函數。

+0

謝謝大衛。我會嘗試。我們可以在TComboBox的OnSelect事件中傳遞整數值嗎? – Nalu

+0

我不明白那個問題 –

+0

TCombobox的Onselect事件有參數(發送者:TObject)。我們可以通過任何其他參數與發件人? – Nalu