6
631229
Unregistered / Unconfirmed
GUEST, unregistred user!
请看这个程序:(调用Api函数GetOpenFileName来显示一个打开文件对话框)<br>unit Unit1;<br>{$APPTYPE GUI}<br>interface<br>Uses<br> Messages,Sysutils,Commdlg,Windows;<br>Const<br> AppName = 'File Editor';<br>Type<br> TFileName = Array[0..Max_Path] Of Char;<br>Var<br> AMessage : Msg;<br> HWindow,HStatus,HEdit : HWnd;<br> TheLogFont : TLogFont;<br> TheColor : DWORD;<br> FileName : TFileName;<br><br>implementation<br><br>Function SelectFile(Var FName:TFileName; Open:Boolean): Boolean;<br>Const<br> Filter : PChar = 'Text files (*.txt)'#0'*.txt'#0+<br> 'All files (*.*)'#0'*.*'#0#0;<br> Ext : PChar = 'txt';<br>Var<br> NameRec : OpenFileName;<br>Begin<br> FillChar(NameRec,SizeOf(NameRec),0);<br> FName[0] := #0;<br> With NameRec Do<br> Begin<br> LStructSize := SizeOf(NameRec);<br> HWndOwner := HWindow;<br> LpStrFilter := Filter;<br> LpStrFile := @FName;<br> NMaxFile := Max_Path;<br> Flags := OFN_Explorer Or OFN_HideReadOnly;<br> If Open Then<br> Begin<br> Flags := Flags Or OFN_FileMustExist;<br> End;<br> LpStrDefExt := Ext;<br> End;<br> If Open Then<br> SelectFile := GetOpenFileName(@NameRec)<br> Else<br> SelectFile := GetSaveFileName(@NameRec);<br>End;<br>...<br>...<br>编译时显示这行出错:SelectFile := GetOpenFileName(@NameRec)<br>[Error] Unit1.pas(75): Types of actual and formal var parameters must be identical<br>即:形参与实参类型不匹配,请帮助分析问题出在哪里?以下是Delphi的windows sdk帮助中<br>有关结构OPENFILENAME的定义,恕我愚笨,我看了很多Delphi的帮助,而且浏览了很多讲述Api<br>的英文网站,但还是没有搞明白。<br>typedef struct tagOFN { // ofn <br> DWORD lStructSize; <br> HWND hwndOwner; <br> HINSTANCE hInstance; <br> LPCTSTR lpstrFilter; <br> LPTSTR lpstrCustomFilter; <br> DWORD nMaxCustFilter; <br> DWORD nFilterIndex; <br> LPTSTR lpstrFile; <br> DWORD nMaxFile; <br> LPTSTR lpstrFileTitle; <br> DWORD nMaxFileTitle; <br> LPCTSTR lpstrInitialDir; <br> LPCTSTR lpstrTitle; <br> DWORD Flags; <br><br> WORD nFileOffset; <br> WORD nFileExtension; <br> LPCTSTR lpstrDefExt; <br> DWORD lCustData; <br> LPOFNHOOKPROC lpfnHook; <br> LPCTSTR lpTemplateName; <br>} OPENFILENAME; <br>