Solved

OpenDialog - filtered filelist?

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

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 25

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

11 Experts available now in Live!

Get 1:1 Help Now