同步通用TList和TListBox时出现问题 [英] Trouble synchronizing generic TList and TListBox

查看:82
本文介绍了同步通用TList和TListBox时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使TListbox与TList保持同步.每次将项目添加到通用TList时,都会调用OnNotify,并且回调仅调用一个过程:create_gradients.其代码如下:

I have trouble keeping a TListbox in sync with a TList. Each time an item is added to a generic TList, OnNotify is called and the callback calls just one procedure: create_gradients. Its code is below:

  procedure TColor_Dialog.create_gradients;
  var Editor: TGradient_Editor;
      eGradient: Int32;
      y: single;
      s: string;
  begin
     List_Names.Clear;
     List_Gradients.Clear;

     for eGradient := 0 to FColor_Editor.nGradients - 1 do
     begin
        List_Names.Items.Add (FColor_Editor [eGradient].Check_Rainbow.Text);
     end; // for

     List_Gradients.BeginUpdate;
     try
        for eGradient := 0 to FColor_Editor.nGradients - 1 do
        begin
           Editor := FColor_Editor [eGradient];
           y := (eGradient + 1) * Editor.Height;
           Editor.Position.Y := y;
           s := Editor.Check_Rainbow.Text;
           List_Gradients.AddObject (Editor);
        end; // for
     finally
        List_Gradients.EndUpdate;
     end; // try..finally
  end; // create_gradients //

如您所见,它只是枚举列表中的所有项目.列表中的每个项目都是TGradient_Editor,而TGradient_Editor又将TFrame作为父项.在父级上是一些FMX控件,如combolorboxes,图像和复选框(Check_Rainbow). Check_Rainbow.Text用于识别目的.创建渐变编辑器后,它将从frame_%s创建一个唯一的名称,其中%s是每次创建渐变编辑器时都会递增的序列号. OwnerParent都是List_Gradients.

As you see it simply enumerates all items in the list. Each item in the list is a TGradient_Editor which in turn has TFrame as a parent. On the parent are some FMX controls as combolorboxes, an image and a checkbox (Check_Rainbow). Check_Rainbow.Text is used for identification purposes. When the gradient editor is created, it creates a unique name from frame_%s where %s is a sequence number that is incremented each time a gradient editor is created. Owner and Parent are both List_Gradients.

从上图可以看到发生了什么.右边的列表框已添加以进行检查,并仅显示文本,顺便说一句,这是正确的顺序.当我使用调试器来跟随将渐变编辑器添加到List_Gradient时,它们将以相同的顺序进行处理.但是渐变编辑器的顺序是错误.我不得不提到渐变编辑器的功能是alTop.我甚至添加了一些代码来确保编辑器位于List_Gradients的最底部.

From the image above you can see what happens. the listbox on the right is added for checking and just shows the text's, which is the correct sequence by the way. When I use the debugger to follow the addition of the gradient editors to List_Gradient they are processed in the same order. But the order of the gradient editors is wrong. I have to mention that the aligment of the gradient editors is alTop. I added even some code to ensure that the editor is Positioned at the very bottom of the List_Gradients.

我似乎不明白某些内容.我无法想象顺序添加到TListBox不能导致正确的顺序.我在做什么错了?

I appear not to understand something. I cannot imagine that sequential adding to a TListBox cannot result in the correct order. What am I doing wrong?

推荐答案

尝试以下方法:

procedure TColor_Dialog.create_gradients;
var
  Editor: TGradient_Editor;
  eGradient: Int32;
  y: single;
begin
  List_Names.Clear;
  List_Gradients.Clear;

  for eGradient := 0 to FColor_Editor.nGradients - 1 do
  begin
    List_Names.Items.Add (FColor_Editor[eGradient].Check_Rainbow.Text);
  end;

  List_Gradients.BeginUpdate;
  try
    y := 0.0; // or whatever value you want to start at...
    for eGradient := 0 to FColor_Editor.nGradients - 1 do
    begin
      Editor := FColor_Editor[eGradient];
      Editor.Position.Y := y;
      List_Gradients.AddObject(Editor);
      y := y + Editor.Height;
    end;
  finally
    List_Gradients.EndUpdate;
  end;
end;

这篇关于同步通用TList和TListBox时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆