?
Solved

Using ListBoxes dramatically slows my program

Posted on 1997-11-29
6
Medium Priority
?
144 Views
Last Modified: 2010-04-04
Hi ..
  I have an app that reads a file looking for strings specified by the user. I used to have it do they could specify the up to 10 strings via edit boxes, then I'd take the contents of the edit boxes and move it to a array of string 10 big. I'd then loop around checking the input file record for any of these 10 strings. This worked OK, but I wanted to allow the user to input an unlimited number of strings, so I switched over to using a list box for input.
  This slowed the execution of my program by almost 300%! Here's the code I'm using:

for y:=0 to ListBox3.items.count - 1 do
    begin
      x:=0;
      x := Pos(ListBox3.items[y], inrec);
      if x <> 0 then
      begin
        writeln(outfile, inrec);
        goto doagain;
      end;
    end;

.. The code I had before looked almost identical except I used string arrays instead of the listbox:

for y:=1 to 10 do
    begin
      x:=0;
      x := Pos(input_str[y], inrec);
      if x <> 0 then
      begin
        writeln(outfile, inrec);
        goto doagain;
      end;
    end;

.. How can I get around this? I really have to use listBoxes
so I can accept a lot of strings easily, but it really seems to be slowing me down!!

Regards,
  Shawn
0
Comment
Question by:aztec
[X]
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
6 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1352423
I guess the only way is keeping with the array of strings, and use the ListBox just to show the strings to the user.
0
 

Author Comment

by:aztec
ID: 1352424
I don't want to use just arrays of strings because I had a lot of string arrays in my program before and it blew it out of the water. The user could potentially add a lot of strings and to make a string array hundreds big would crash my program like before. Can't I use pointers to strings? I've heard this may help me, but I don't know how to do it??

Shawn
0
 
LVL 1

Accepted Solution

by:
anilms earned 100 total points
ID: 1352425
You can do this - use the ListBox for UI purposes only and then use a Linked List for storing all the strings. You have two choices here - either to create your own list handling functions or to use a TList object. The TList object is faster than the ListBox but if you define your own list processing functions, it will be faster still. You will have to write code to add,delete and traverse a list. You can avoid all this if you use TList. TList is basically a collection of pointers.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:anilms
ID: 1352426
Sorry, the above was not an answer - it was more of a guideline. I did not purposefully put it as an answer. I can give an answer based on more input.
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1352427
Agreed with you both; i said 'array of strings' just for the sake of simplicity.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1352428
how do you ascertain that using listbox is 300 times slower?
I tested you code and found that there are not much difference in speed of both method. This is true event with the use of memo box. Is there any thing wrong in your 'doagain' code?
May be I have misunderstood your requirement. Could you give us more detail.
The following are my test program which use
a. array of string
b. listbox
c. memo
(Note that I have remove the goto statement for [b] and [c].)

procedure TForm1.Button1Click(Sender: TObject);
var x, y: integer;
label doagain;
begin
  for x:=1 to 10 do
    input_Str[x]:= listbox1.items[x-1];
  doagain:
  inrec:= InputBox('Data entry', 'Data = ', '');
  for y:=1 to 10 do begin
    x:=0;
    x := Pos(input_str[y], inrec);
    if x <> 0 then begin
      writeln(outfile, inrec);
      goto doagain;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var x, y: integer;
begin
 while InputQuery('Data entry',
    'Click [OK] to confirm or [Cancel] to quit:', inrec) do begin
   for y:=0 to ListBox1.items.count - 1 do begin
     x:=0;
     x := Pos(ListBox1.items[y], inrec);
     if x <> 0 then
       writeln(outfile, inrec);
   end;
 end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var x, y: integer;
begin
  while InputQuery('Data entry',
    'Click [OK] to confirm or [Cancel] to quit:', inrec) do begin
    for y:=0 to memo1.lines.count - 1 do begin
      x:=0;
      x := Pos(memo1.lines[y], inrec);
      if x <> 0 then
        writeln(outfile, inrec);
    end;
  end;
end;


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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 this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 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