Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

13 Experts available now in Live!

Get 1:1 Help Now