[lazarus] TFileDialog - Filter.

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Jul 21 09:40:37 EDT 2003


On Mon, 21 Jul 2003 08:46:59 -0400
Bob Wingard <bwingard at gt.rr.com> wrote:

> Mattias Gaertner wrote:
>  >snip
> 
> >What filter were not properly parsed?
> >
>  >snip

First of all: The filter in TFileDialog does not work very well, because the
gtk file selection dialog does not support them. Only very basic globbing. I
think, you already noticed that. It can be fixed by connecting to all input
events of the gtk file selection dialog, but then we are not far away from
writing our own filedialog.

 
> The problem was in the section of code that parsed the Filter property 
> of the TFileDialog class. The code extracts a Description and Filter 
> from the string property Filter. According to comments in the code it 
> was looking for a string formated 

> '|description1|filter1|description2|filter2|....' 
   ^
This is not a valid filter. See comments in the code for an example.


> After parseing you end 
> up with a list of descriptions that go in the pull down menu on the file 
> dialog and a list of masks that go with the description.


Mattias



> 
> Comments from the code:
> {------------------------------------------------------------------------
> ------
>   Function: ExtractFilterList
>   Params: const Filter: string; var FilterIndex: integer;
>           var FilterList: TStringList
>   Returns: -
> 
>   Converts a Delphi file filter of the form
>   'description1|mask1|description2|mask2|...'
>   into a TList of PFileSelFilterEntry(s).
>   Multi masks:
>     - multi masks like '*.pas;*.pp' are converted into multiple entries.
>     - if the masks are found in the description they are adjusted
>     - if the mask is not included in the description it will be
>     concatenated For example:
>       'Pascal files (*.pas;*.pp)|*.pas;*.lpr;*.pp;
>       is converted to three filter entries:
>         'Pascal files (*.pas)' + '*.pas'
>         'Pascal files (*.pp)'  + '*.pp'
>         'Pascal files (*.lpr)' + '*.lpr'
>  ------------------------------------------------------------------------
>  ------}
> This is the section that had the error.
> 
>  procedure ExtractMasks(const MultiMask: string);
>   var CurMaskStart, CurMaskEnd: integer;
>     s: string;
>   begin
>     if Masks=nil then
>       Masks:=TStringList.Create
>     else
>       Masks.Clear;
>     CurMaskStart:=1;
>     while CurMaskStart<=length(MultiMask) do begin
>       CurMaskEnd:=CurMaskStart;
>       while (CurMaskEnd<=length(MultiMask)) and 
> (MultiMask[CurMaskEnd]<>';') do
>         inc(CurMaskEnd);
>       s:=Trim(copy(MultiMask,CurMaskStart,CurMaskEnd-CurMaskStart));
>       if s='*.*' then s:='';
>       Masks.Add(s);
>       CurMaskStart:=CurMaskEnd+1;
>     end;
>   end;
> 
> 
> 
> _________________________________________________________________
>      To unsubscribe: mail lazarus-request at miraclec.com with
>                 "unsubscribe" as the Subject
>    archives at http://www.lazarus.freepascal.org/mailarchives


-- 






More information about the Lazarus mailing list