Changeset 240 for Common/UCommon.pas


Ignore:
Timestamp:
May 4, 2011, 1:21:07 PM (13 years ago)
Author:
george
Message:
  • Added: Routines for opendialog file extension evaluation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r146 r240  
    44
    55uses
    6   Windows, Classes, SysUtils, SpecializedList, StrUtils; //, ShFolder, ShellAPI;
     6  Windows, Classes, SysUtils, SpecializedList, StrUtils, Dialogs; //, ShFolder, ShellAPI;
    77
    88type
     
    4343function LastPos(const SubStr: String; const S: String): Integer;
    4444function GenerateNewName(OldName: string): string;
     45function GetFileFilterItemExt(Filter: string; Index: Integer): string;
     46procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
     47
    4548
    4649implementation
     50
     51function GetFileFilterItemExt(Filter: string; Index: Integer): string;
     52var
     53  List: TStringList;
     54begin
     55  try
     56    List := TStringList.Create;
     57    List.Text := StringReplace(Filter, '|', #10, [rfReplaceAll]);
     58    Result := List[Index * 2 + 1];
     59  finally
     60    List.Free;
     61  end;
     62end;
     63
     64procedure FileDialogUpdateFilterFileType(FileDialog: TOpenDialog);
     65var
     66  FileExt: string;
     67begin
     68  FileExt := GetFileFilterItemExt(FileDialog.Filter, FileDialog.FilterIndex - 1);
     69  Delete(FileExt, 1, 1); // Remove symbol '*'
     70  if FileExt <> '.*' then
     71    FileDialog.FileName := ChangeFileExt(FileDialog.FileName, FileExt)
     72end;
    4773
    4874function GenerateNewName(OldName: string): string;
Note: See TracChangeset for help on using the changeset viewer.