Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-19
2
Medium Priority
?
155 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

783 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