Solved

Removing Repeated Data in a Listbox with a lrage amount of data

Posted on 2004-04-19
2
142 Views
Last Modified: 2010-04-05
I have written this code to remove repeated data in a listbox which does do fine for small amounts of items in the data, but when there is more than 400 items the program freeze and is there a way of not making this code crash for large number of items around 900.

procedure TForm1.RemoveRepeats(Sender: TObject);
var i,j :integer;
  valid : boolean;
begin
while valid = false do
  begin
    valid := true;
    for j := 0 to listbox1.Count-1 do
      begin
        for i := 0 to listbox1.Count-1 do
          if (listbox1.Items.Strings[j] = listbox1.Items.Strings[i]) and (j<>i) then
           begin
              listbox1.Items.delete(i);
              valid := false;
              break;
           end;
         if valid = false then
           break;
      end;
  end;
end;
0
Comment
Question by:jlix
2 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 75 total points
ID: 10858786
maybe this way?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Procedure DeleteDups(AList : TStrings);
var
  sl : TStringList;
begin
  sl := TstringList.Create;
  sl.Sorted := true;
  sl.Duplicates := dupIgnore;
  sl.Assign(AList);
  AList.Assign(sl);
  sl.Free;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  DeleteDups(listbox1.Items);
end;

end.


meikl ;-)
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10858833
exactly how I'd do it :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question