Solved

Narrowing list content like in MS Outlook Express

Posted on 1998-08-21
12
127 Views
Last Modified: 2010-04-04
I am trying to duplicate some functionality found in MS Outlook Express where a list of Newsgroup is displayed. Then the user can enter a string to display newsgroups that contain that string.

Any idea how this can be implemented ?
0
Comment
Question by:moonrise
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1337398
Is it incremental searching that you want to do?? Like enter a string in the edit box and if this string is contained in any of the words for example in a listbox, then it gets selected???

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:nrobin
ID: 1337399
Depending on what your data structures you're using, you could if storing the newsgroups in a database, use the like sql statement.  When the text changes, re-submit the sql and then update the listview.  The speed may be of concern when the size is exceptinally large.
0
 
LVL 1

Expert Comment

by:nrobin
ID: 1337400
Depending on what your data structures you're using, you could if storing the newsgroups in a database, use the like sql statement.  When the text changes, re-submit the sql and then update the listview.  The speed may be of concern when the size is exceptinally large.

Regards
Nicholas Robinson
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337401
What you could do is this...Have a listbox that loads its items from a datebase or from a file, and have an edit box that is on the top of the listbox....Sort the items in the listbox, and enter this in the OnChange event of the editbox....

procedure TForm1.Edit1Change(Sender: TObject);
var
  S : Array[0..255] of Char;
begin
  StrPCopy(S, Edit1.Text);
  with ListBox1 do
    ItemIndex := Perform(LB_SELECTSTRING, 0, LongInt(@S));
end;

this would set the index on the string that is contained in any of the fields of the listbox...

For example
______
|am        |
|abd       |
|abcde   |
|db         |
|______|

That's the listbox with the items.....
IF = If you type

IF a then ItemIndex := 0;
IF ab then ItemIndex := 1;
IF db then ItemIndex := 3;
and so on....

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:nrobin
ID: 1337402
Viktors solution is the most simple and easiest way to do this.  If you simply want to select the item, then sending the LB_SELECTSTRING is a good solution.  However if you want the view to look and act like MS's, then that will not do.  

-N.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337403
Hello nrobin. How does the Outlook looks anyway? Maybe it's got a nice interface, huh?

Regards,
Viktor Ivanov
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:nrobin
ID: 1337404
The interface is quite nice.  If you can imagine a form with an edit box at the top to enter the newsgroup name in, then a listview sits underneath with all the newsgroups.  Everytime you press a key in the editbox, the listview contains a shortened view.  So if you type alt., then within a few seconds all the items with the entered text are displayed.  Threads are obviously used to do the updating of the list - a key point.

Regards
Nicholas Robinson.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337405
Yes you can do this then..

var
    List : TStringList;
begin
    for i := 0 to List.Items.Count - 1 do
    begin
        if Pos(edit.text, List.Items[i]) then
            ListBox.Items.Add(List.Items[i]);
    end;
end;

Hope this helps =)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337406
Actually this is the right code....

var
         List : TStringList;
     begin
         ListBox.Clear;
         for i := 0 to List.Items.Count - 1 do
         begin
             if Pos(edit.text, List.Items[i]) then
                 ListBox.Items.Add(List.Items[i]);
         end;
//vik
     end;
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337407
Hi,
Here's an example of getting the same functionality as MS Outlook Express:

  ...
  private
    m_listGroups       : TStringList;
    m_bCriteriaChanged : Boolean;
    procedure SearchGroups( sSubStr: string );
    { Private declarations }
  end;

  ...
procedure TForm1.FormCreate(Sender: TObject);
begin
  if ( not FileExists( 'c:\newsgroups.dat' ) ) then
  begin
    _NNTP1.Login; // uses Andreas Hörstemeier's TCP/IP...
    _NNTP1.GetAllNewsgroups;
    _NNTP1.Logout;
    _NNTP1.NewsGroups.SaveToFile( 'c:\newsgroups.dat' );
  end;
  m_listGroups := TStringList.Create;
  m_listGroups.LoadFromFile( 'c:\newsgroups.dat' );
end;

procedure TForm1.SearchGroups( sSubStr: string );
var
  iIndex: Integer;
  bEmpty: Boolean;
begin
  Screen.Cursor := crHourGlass;
  m_bCriteriaChanged := False;
  try
    sSubStr := LowerCase( sSubStr );
    ListView2.Items.BeginUpdate;
    ListView2.Items.Clear;
    bEmpty := sSubStr = '';
    for iIndex := 0 to m_listGroups.Count - 1 do begin
      if ( bEmpty ) or ( Pos( sSubStr, LowerCase( m_listGroups[ iIndex ] ) ) > 0 )
      then with ListView2.Items.Add do begin
        Caption := m_listGroups[ iIndex ];
        Data    := m_listGroups.Objects[ iIndex ];
      end;
      Application.ProcessMessages; // allow abortion...
      if ( m_bCriteriaChanged )
      then Break;
    end;
  finally
    ListView2.Items.EndUpdate;
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  Timer1.Enabled  := False;
  m_bCriteriaChanged := True;
  Timer1.Interval := 500;
  Timer1.Enabled  := True;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if ( Key = #13 )
  then begin
    Key := #0; // remove error beep
    Timer1.Enabled := False;
    SearchGroups( Edit1.Text );
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  SearchGroups( Edit1.Text );
end;

Really easy, but quite sufficient...

/// John
0
 

Author Comment

by:moonrise
ID: 1337408
Thank you all. erajoj has the perfect answer. It works great. How do I give erajoj the points ?
0
 
LVL 4

Accepted Solution

by:
erajoj earned 90 total points
ID: 1337409
By accepting this measly answer with very good marks! :-)

/// John
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

11 Experts available now in Live!

Get 1:1 Help Now