procedure TForm1.Button1Click(Sender: TObject);
var    i:integer;
       TempList:TlistBox;begin
    TempList:=TListBox.Create(self);
  for i:=0 to listbox1.Items.Count-1 do
   begin
     if not listbox1.Selected[i] then
       begin
       TempList.Items.Add(listbox1.items[i]);
       end;
   end;
 listbox1.Clear;
 for i:=0 to Templist.Items.count -1 do
   begin
   Listbox1.Items.Add(TempList.items[i]);
   end;
 TempList.Clear;
end;
    //报错信息为:Control '' has no parent window 
  请问如何解决....

解决方案 »

  1.   


    TempList:=TListBox.Create(self);  
    后加:
    TempList.Visible := False;
    TempList.Parent := Listbox1.Parent;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var    i:integer;
           TempList:TlistBox;begin
        TempList:=TListBox.Create(self);
      for i:=0 to listbox1.Items.Count-1 do
       begin
         if not listbox1.Selected[i] then
           begin
           TempList.Items.Add(listbox1.items[i]);
           end;
       end;
     listbox1.Items.Clear;
     for i:=0 to Templist.Items.count -1 do
       begin
       Listbox1.Items.Add(TempList.items[i]);
       end;
     TempList.Items.Clear;
    end;
      

  3.   

    另外:其中的TempList用TStrings或者Array of string代替就可以了,没有必要使用一个TListBox对象。————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————