2017-07-16 83 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