2012-11-26 31 views
0

如何在FileDialog OnTypeChange事件中獲取FileDialog的FileTypeIndex?如何在TFileDialog.OnTypeChange事件中獲取piFileType

function TFileDialogEvent.OnTypeChange(const pfd: IFileDialog): 
    HResult; stdcall; 
var 
    iCaption: string; 
    iFilename: PWideChar; 
begin 
    {Get the current filename} 
    pfd.GetFileName(iFilename); 
    {Get the classname of the dialog to set the caption} 
    if FClassName = 'TIEWin7FileOpenDialog' then 
     iCaption := 'Open- ' + iFilename 
    else 
     iCaption := 'Save As- ' + iFilename; 
    pfd.SetTitle(PWideChar(iCaption)); 
    FileTypeIndex := pfd.GetFileTypeIndex(???); 
end; 
+1

'var FileTypeIndex:UINT;如果成功則開始(pfd.GetFileTypeIndex(FileTypeIndex))然後{你得到它}結束;'。 – TLama

+0

這應該清楚從MSDN文檔。 –

+0

仍然需要第二個問題的答案......我爲此開發了一個新問題。 – Bill

回答

3

IFileDialog::GetFileTypeIndex的文檔包含答案。該方法的C++簽名是:

HRESULT GetFileTypeIndex(
    [out] UINT *piFileType 
); 

這相當於德爾福爲:

function GetFileTypeIndex(out FileType: UINT): HRESULT; 

這就是說,在Delphi翻譯ShlObj聲明參數是var這是語義上不正確。碰巧它並不重要。

把它放在一起,你的代碼應該這樣寫:

OleCheck(pfd.GetFileTypeIndex(FileTypeIndex)); 

注意,我添加了一些錯誤檢查。你也應該。您的問題中的代碼調用三種不同的COM方法,並且在每種情況下都無法檢查錯誤。

+1

好的,謝謝...... Upvoted並將OleCheck添加到我所有的pfd調用中。 – Bill

相關問題