Solved

OpenDialog - filtered filelist?

Posted on 2013-06-09
5
432 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
[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
  • 3
  • 2
5 Comments
 
LVL 27

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 27

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TServerSocket - file via sendbuf or Text via sendtext ? 1 92
Create a path if not exists 7 128
TEMBEDDEDWB how can i change its user agent ? 8 106
CheckListBox usage 3 98
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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