Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 63
How to debug For loops? 3 45
Unique identifier on a terminal server (rdp) 4 46
Dynamically Created Query 3 50
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now