【问题标题】:On click event dynamic object reference点击事件动态对象引用
【发布时间】:2017-07-16 12:33:20
【问题描述】:

我在运行时创建了未知数量的标签并添加到点击事件处理程序中。找出我点击了哪个标签的代码是什么?

谢谢。

【问题讨论】:

    标签: delphi dynamicobject


    【解决方案1】:

    刚发完问题,我终于找到了答案:|

    我需要在点击事件中使用 (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;
    

    【讨论】:

    • 请注意,每个标签的适当标签值可以简化任务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 2016-06-02
    • 2012-02-11
    • 1970-01-01
    相关资源
    最近更新 更多