function CopyItem(Source, Dest: TListBox): Integer; var I: Integer; begin Result := 0; I := 0; while I < Source.Count do begin if (Source.Selected[I]) and (Dest.Items.IndexOf(Source.Items[I]) = -1) then begin Dest.Items.Add(Source.Items[I]); Source.Items.Delete(I); Result := Result + 1; end else Inc(I); end; end;procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text := IntToStr(CopyItem(ListBox1,ListBox2)); end;
严重同意一楼!! 好吧我姑且认为这不是一个人发的,再回答一次: procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin ListBox2.Items.Clear; for i:=0 to ListBox1.Items.Count-1 do if ListBox2.Items.IndexOf(ListBox1.Items.Strings[i])>0 then continue else ListBox2.Items.Add(ListBox1.Items.Strings[i]); ListBox1.Items.Clear; end;
var
I: Integer;
begin
Result := 0;
I := 0;
while I < Source.Count do
begin
if (Source.Selected[I]) and
(Dest.Items.IndexOf(Source.Items[I]) = -1) then
begin
Dest.Items.Add(Source.Items[I]);
Source.Items.Delete(I);
Result := Result + 1;
end
else Inc(I);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := IntToStr(CopyItem(ListBox1,ListBox2));
end;
好吧我姑且认为这不是一个人发的,再回答一次:
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
ListBox2.Items.Clear;
for i:=0 to ListBox1.Items.Count-1 do
if ListBox2.Items.IndexOf(ListBox1.Items.Strings[i])>0 then continue
else ListBox2.Items.Add(ListBox1.Items.Strings[i]);
ListBox1.Items.Clear;
end;
应该如何计算有多少条记录被复制了?