2017-07-16 118 views
-2

我在運行時創建了未知數量的標籤並添加了單擊事件處理程序。什麼是代碼來找出我點擊哪個標籤?點擊事件動態對象引用

謝謝。

回答

0

剛發佈問題後我終於找到了答案:

我需要在點擊事件中使用(Sender as TLabel)。

procedure TfrmShowing.lblShowtimesClick(Sender: TObject); 
var 
    iCount : integer; 
begin 
    //Find the clicked on movie 
    for iCount := 0 to Length(arrMoviePanels) do 
    begin 
     if arrMoviePanels[iCount] = (Sender as TLabel).Parent then 
     sClickedMovie := arrMovies[iCount]; 
    end; 
end; 
+0

請注意,適當的標籤值爲每個標籤可以簡化任務。 – MBo