Link to home
Start Free TrialLog in
Avatar of ejla51
ejla51

asked on

OpenDialog - filtered filelist?

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?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

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.
Avatar of ejla51
ejla51

ASKER

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;
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ejla51

ASKER

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)
Avatar of ejla51

ASKER

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

Thanks!