Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-04-19
2
143 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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