Solved

OpenDialog - filtered filelist?

Posted on 2013-06-09
5
430 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 151
Downloading email attachments 2 80
Press three keys together and trigger a function 3 61
delphi popmenu non latine charcters 3 13
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…
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…

828 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