IPlist.Strings[I] := Format('★%5d次★%5f%%★%s', [J,(J/IPlist.Count)*100,IPlist.Strings[I]]);算出的百分比不准~~~~~~~~~完整代码如下:
读取一个含有IP地址的文本,统计出出现次数最多的3个IPprocedure Tipanalyse.btnanalyseClick(Sender: TObject);
var
  J: Integer;
  I: Integer;
  index:Integer;
  IPlist:TStringlist;
  IPtop:TStringlist;
begin
    IPlist:=TStringList.Create;
    IPtop:=TStringList.Create;
    try
    IPlist.LoadFromFile('dnstmplog.txt'); //载入文件
    lbltotal.Caption:= inttostr(IPlist.count);
    IPlist.sort; //排序
    J := 1;
    for I:= IPlist.Count - 1 downto 0 do
    begin
      if (I >= 1) and (IPlist.Strings[I] = IPlist.Strings[I - 1]) then
      begin
        Inc(J);
        IPlist.Delete(I);
      end
      else begin
        IPlist.Strings[I] := Format('★%5d次★%5f%%★%s', [J,(J/IPlist.Count)*100,IPlist.Strings[I]]);
        J := 1;
      end;
    end;
    IPlist.Sort; //排序
    IPlist.SaveToFile('output.txt');    //取最后三行
    IPtop.LoadFromFile('output.txt');
    index:=IPtop.Count;
    lbltop1.Caption:=IPtop.Strings[index-1];
    lbltop2.Caption:=IPtop.Strings[index-2];
    lbltop3.Caption:=IPtop.Strings[index-3];
  finally
    IPlist.Free;
    IPtop.Free;
  end;
end;