Delphi - Clean TListBox Items

Posted by Brad on Stack Overflow See other posts from Stack Overflow or by Brad
Published on 2010-04-22T12:25:32Z Indexed on 2010/04/22 17:23 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

I want to clean a list box by checking it against two other list boxes.

  • Listbox1 would have the big list of items
  • Listbox2 would have words I want removed from listbox1
  • Listbox3 would have mandatory words that have to exist for it to remain in listbox1

Below is the code I've got so far for this, it's VERY slow with large lists.

// not very efficient 
Function checknegative ( instring : String; ListBox : TListBox ) : Boolean;
Var
  i : Integer;
Begin
  For I := listbox.Items.Count - 1 Downto 0 Do
  Begin
    If ExistWordInString ( instring, listbox.Items.Strings [i], 
      [soWholeWord, soDown] ) = True 
    Then
    Begin
      result := True;  //True if in list, False if not.
      break; 
    End
    Else
    Begin
      result := False;
    End;
  End;
  result:=false;
End;

Function ExistWordInString ( aString, aSearchString : String;
  aSearchOptions : TStringSearchOptions ) : Boolean;
Var
  Size : Integer;
Begin
  Size := Length ( aString );
  If SearchBuf ( Pchar ( aString ), Size, 0, 0, aSearchString, aSearchOptions ) <> Nil Then
  Begin
    result := True;
  End
  Else
  Begin
    result := False;
  End;
End;

© Stack Overflow or respective owner

Related posts about delphi-2009

Related posts about delphi