2012-11-26 1 views
3

파일 확장명이 알려진 경우 TFileSaveDialog DoExecute 이벤트의 Extension을 FileTypeIndex로 어떻게 변환합니까?확장명을 알고있는 경우 DoExecute TFileSaveDialog 이벤트에서 FileTypeIndex를 어떻게 설정합니까?

function TIEWin7FileSaveDialog.DoExecute: Bool; 
    begin 
    ... 
    {Set FileType (filter) index} 
    iWideTextension := ExtractFileExt(FileName); 
    FileTypeIndex := ???ExtensionToFileTypeIndex(iWideExtension);??? 
    FileDialog.SetFileTypeIndex(FileTypeIndex); 
    ... 
    end; 
+1

당신은 어 알고 각 파일 유형의 확장자에 있습니다. 그래서 라운드를 반복하여 어느 인덱스와 일치하는지 찾습니다. –

+0

감사합니다. David ... 더 나은 방법이 있거나 일부 기능이 그렇게 할 수 있다고 생각했습니다. – Bill

+0

아니야. 나는 그 주석에 묘사 된 것과 똑같이한다. –

답변

2

이 하나의 파일 형식보다 파일 형식 마스크에 포함 할 수있다 적어도 때문에 원하는 것을 할 것 명시 적 기능이 없다, 그래서 파일 유형이 포함 또는 같음되는 경우에만 FileTypes를 반복하고 확인하실 수 있습니다 같은 FileMask는 다음과 같습니다 :

function FindFirstFileType(FileDialog: TCustomFileDialog; 
    const FileExt: string): UINT; 
var 
    TypeIndex: Integer; 
    ExtIndex: Integer; 
    ExtArray: TStringDynArray; 
begin 
    Result := 0; 
    for TypeIndex := 0 to FileDialog.FileTypes.Count - 1 do 
    begin 
    ExtArray := SplitString(FileDialog.FileTypes[TypeIndex].FileMask, ';'); 
    for ExtIndex := 0 to High(ExtArray) do 
     if ExtArray[ExtIndex] = FileExt then 
     begin 
      Result := TypeIndex; 
      Break; 
     end; 
    end; 
end; 

그리고 사용 (입력 필터 마스크에 정확히 일치해야합니다) :

procedure TForm1.Button1Click(Sender: TObject); 
var 
    I: UINT; 
begin 
    I := FindFirstFileType(FileOpenDialog1, '*.pas'); 
end; 
+0

여러분을 환영합니다! – TLama