Solved

Narrowing list content like in MS Outlook Express

Posted on 1998-08-21
12
134 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
[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
  • 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
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 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
 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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