【问题标题】:Dynamic array in delphidelphi中的动态数组
【发布时间】:2011-10-01 03:04:17
【问题描述】:

我在delphi 7中创建了一个TLabel和TCombobox的打包对象(TMyComponent)。 我创建了一个 TMyComponent 的动态数组(MyArray)。现在点击添加按钮,我增加了 MyArray 的长度并创建了 TLabel 和 TCombobox 的对象并显示在屏幕上。如果我添加了 5 个组件,我们如何获取 Myaaray 的当前选定组件意味着如果我从屏幕中选择了第 3 个组件,那么我如何获得值 3 作为回报?感谢帮助

【问题讨论】:

    标签: delphi delphi-7


    【解决方案1】:

    我认为您正在寻找这样的功能:

    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;
    

    我相信如何调用这个函数会很明显。

    【讨论】:

    • 谢谢大卫。我会试试。我们可以在 TComboBox 的 OnSelect 事件中传递整数值吗?
    • 我不明白这个问题
    • TCombobox 的 Onselect 事件有参数(Sender:TObject)。我们可以将任何其他参数与 Sender 一起传递吗?
    • 您不能更改内置事件的参数列表。您也许可以从发件人那里读取信息。
    • @naren 您应该发布另一个问题,但是您可以对发件人进行强制转换并使用 Tag 属性来存储整数值,即 TComboBox(Sender).Tag
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多