条目是连续的导入没问题,要是选择的不是连续的就不对了(选择的是前几个(选择三个就是前三条)),谁能帮我改一改呢?代码如下
procedure Tf_main.sB_swyy2Click(Sender: TObject);
var
 Iitemno,Ino,i: Integer;
 ifsame:boolean;
begin
  Iitemno:=0;
  with sLB_swyyqb do
  for Ino:=0 to Items.Count-1 do
  begin
    if Selected[Ino] then
    begin
      Iitemno:=Ino;
      Break;
    end;
  end;  ifsame:=false;
  with sLB_swyyqb do
  begin
    for Ino:=Iitemno to Iitemno+(sLB_swyyqb.SelCount-1) do
    begin
      for i:=0 to sLB_swyyxz.Items.Count-1 do
      begin
        if Items[Ino]= sLB_swyyxz.Items[i] then
        begin
          ifsame:=true;
          break;
        end;
        ifsame:=false;
      end;
      if ifsame=false then sLB_swyyxz.Items.Add(Items[Ino]);
    end;
  end;
end;

解决方案 »

  1.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
            i: integer;
    begin
            for i:=0 to ListBox1.Count -1 do
            begin
                    if ListBox1.Selected[i] then
                    begin
                            if ListBox2.Items.IndexOf(ListBox1.Items.Strings[i])<0 then
                                    ListBox2.Items.Add(ListBox1.Items.Strings[i]);
                    end;
            end;
    end;