Solved

Narrowing list content like in MS Outlook Express

Posted on 1998-08-21
12
128 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
how to draw animated progressbar in Tvirtualstringtree 5 116
delphi prevent click fast 2 189
PHP preg_replace code convert to Delphi 14 33
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 tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

19 Experts available now in Live!

Get 1:1 Help Now