Solved

Narrowing list content like in MS Outlook Express

Posted on 1998-08-21
12
130 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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