我定义了两个Tobjectlist对象,一个放旧的托盘列表(traylist), 一个获得当前最新的托盘列表(traylist_new), 然后从新的托盘列表中更新旧的托盘列表,
添加新托盘的代码如下:
var
  i,j:integer;
  traylist_new := getTraylist(traylist_new);
  for i := 0 to traylist_new.Count - 1 do
  begin
    for j := 0 to traylist.Count - 1 do
    begin      if Ttrayitem(traylist_new.Items[i]).idcommand =
        Ttrayitem(traylist.Items[j]).idcommand then
        break
      else
      begin
        if j = traylist.Count - 1 then
        begin          traylist.Add(traylist_new.Items[i]);
          ShowMessage('又加了一个');        end;
      end;
    end;
  end;
删除旧托盘的的代码如下:
  for i := 0 to traylist.Count - 1 do
  begin
    for j := 0 to traylist_new.Count - 1 do
    begin
    if Ttrayitem(traylist.Items[i]).idcommand =
        Ttrayitem(traylist_new.items[j]).idcommand then
        Break
      else
      begin
        if (j = traylist_new.Count-1 ) and (Ttrayitem(traylist.Items[i]).visible = True)  then
        begin
          traylist.Delete(i);
          traylist.Pack;
        end;
      end;
    end;我隐藏一个托盘后,按理应该是要从traylist里减少一个托盘的,但是delete的那个托盘是删掉了,不过却自动把第一个托盘加到了这个位置.是怎么回事如图: