Solved

OpenDialog - filtered filelist?

Posted on 2013-06-09
5
426 Views
Last Modified: 2013-06-14
I want to have filtered TOpenDialog filelist matching to preset filename mask.
E.g.
 OpenDialog.Filename := filepath + 'MyDocs*' +'*.doc';
 OpenDialog.Execute;
...
Only files named initial as "MyDocs..." would be visible in the OpenDialog filelist?
 
How to do?
0
Comment
Question by:ejla51
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39233380
You can add in design mode or in code this property:
  OpenDialog1.Filter := 'Document files (*.doc)|*.doc';
  OpenDialog1.DefaultExt := '.doc';

Open in new window


... property FileName is for setting destination/source file.
0
 

Author Comment

by:ejla51
ID: 39233421
This filter have affect only to file extensions, not names.
I want to show filenames, e.g. all files witch match to "MyDoc*.doc'.  (MyDoc1, MyDoc2, MyDoc3,etc).

Have tried something as below:

ListFiles(prg.FilePath, 'MyDoc*.doc', OpenDialog1.Files);
// This does not update files in the OpenDialog....

procedure ListFiles(const AFolder, AFilter: string; AList: TStrings);
var
  vFindHandle: THandle;
  vFilter    : String;
  vFindData  : WIN32_FIND_DATA;
begin
  AList.BeginUpdate;
  try
    AList.Clear;
    vFilter := AFolder + '\' + AFilter;
    vFindHandle := FindFirstFile(PChar(vFilter), vFindData);
    if vFindHandle = INVALID_HANDLE_VALUE then  Exit;
    repeat
      AList.Add(ChangeFileExt(vFindData.cFileName, ''));
    until not FindNextFile(vFindHandle, vFindData);
    Windows.FindClose(vFindHandle);
  finally
    AList.EndUpdate;
  end;
end;
0
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39233886
Then it should be:
OpenDialog1.Filter := 'MyDoc files (MyDoc*.doc)|MyDoc*.doc';

Open in new window

0
 

Author Comment

by:ejla51
ID: 39235484
Ok, I agree this works as is... but I have to use a variabel to identify users and allow select  only respective users files

us := usr.LoggedUser;

OpenDialog1.Filter := us + ' logs ('+ us + '*.log)|us + *.log';

Seems good, but a still a little problem... This does not work :-(
(Hardcoded  filter does work fine)
0
 

Author Comment

by:ejla51
ID: 39235716
Found it ...
  us := usr.LoggedUser;
  flt := 'Logfiles (' + us + '*.log)|' + us + '*.log';
  OpenDialog1.Filter := flt;

Thanks!
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

18 Experts available now in Live!

Get 1:1 Help Now