2,497
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.Button1Click(Sender: TObject);
var
V: tstringlist;
i:Integer;
begin
V:= tstringlist.Create;
V.LoadFromFile('d:\abc.txt');
i:=V.Count-1;
if i=0 then
Exit;
while 1=1 do
begin
if V.IndexOf(V.Strings[i]) <> i then
V.Delete(i);
Dec(i);
if i=0 then
Break;
end;
V.SaveToFile('d:\abc.txt');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Clear;
ListBox1.Items.Add('2');
ListBox1.Items.Add('1');
ListBox1.Items.Add('3');
ListBox1.Items.Add('2');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
ListBox1.Sorted := True;
i := 0;
while (i < ListBox1.Count - 2) do
begin
if ListBox1.Items.Strings[i] = ListBox1.Items.Strings[i+1] then
begin
ListBox1.Items.Delete(i+1);
Continue;
end;
Inc(i);
end;
end;