星期六编程发现了Borland delphi7的几个错误。
1 在win32 api中有如下一个函数:
The ExtractIconEx function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.
HICON ExtractIconEx(
LPCSTR lpszFile,
int nIconIndex,
HICON FAR * phiconLarge,
HICON FAR * phiconSmall,
UINT nIcons
);
Parameters
lpszFile
Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file.
nIconIndex
Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file. If this value is -1 and phIconLargeand phiconSmall are both NULL, the function returns the total number of icons in the specified file.
phiconLarge
Pointer to an array of handles of large icons returned. This parameter can be NULL.
phiconSmall
Pointer to an array of handles of small icons returned. This parameter can be NULL.
nIcons
Specifies the count of the number of icons to extract.
Return Values
If the function succeeds, the return value is the handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return value is 1. If no icons were found in the file, the return value is NULL.
在Borland delphi7的shellapi.Pas文件中却声明成这样:
{$EXTERNALSYM ExtractIconEx}
function ExtractIconEx(lpszFile: PChar; nIconIndex: Integer;
var phiconLarge, phiconSmall: HICON; nIcons: UINT): UINT; stdcall;
原型是HICON指针,Borland直接声明成HICON。
如要使用这个函数只好重新声明。
给大家一个声明的例子:
type ThIconArray = array[0..0] of hIcon;
type PhIconArray = ^ThIconArray;
function ExtractIconEx(lpszFile: PAnsiChar;
nIconIndex: Integer;
phiconLarge : PhIconArray;
phiconSmall: PhIconArray;
nIcons: UINT): UINT; stdcall;
external 'shell32.dll' name 'ExtractIconEx';
2Delphi7 sdk帮助里的这个函数也有问题:
The ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.
HICON ExtractIcon(
HINSTANCE hInst, // instance handle
LPCTSTR lpszExeFileName, // filename of file with icon
UINT nIconIndex // index of icon to extract
);
Parameters
hInst
Identifies the instance of the application calling the function.
lpszExeFileName
Points to a null-terminated string specifying the name of an executable file, DLL, or icon file.
nIconIndex
Specifies the index of the icon to retrieve. If this value is 0, the function returns the handle of the first icon in the specified file. If this value is -1, the function returns the total number of icons in the specified file.
Return Values
If the function succeeds, the return value is the handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.
NIconIndex为UNIT型不能取负,注释却说“If this value is -1, the function returns the total number of icons in the specified file.”但返回值却没有提到可以返回 “the total number of icons in the specified file”。实际使用中确实也不能取-1,不过好想delphi5中可以这样用。Borland的文档真是叫人受不了。
3Delphi7中公布了alphablend这个属性,可以在2000以上中实现窗体透明,但在98中不行。如果在98中用alphablend这个win32 api函数自己实现窗体透明,编译器又会报错(和属性同名肯定会啦)。