Delphi7开发的Ocx控件提示DAX Error的解决办法

据说delphi5到delphi7一直有这个bug,不知道更高的版本有没有改过来

我用的是delphi7

对Delphi了解得并不多,这次写ocx也是赶鸭子上架。所以这个bug的原因我也说不明白,但是确实把问题解决了,下面把解决方法说一下(其实也都是从网上搜的,稍加整理)

1、到delphi安装目录下,找到Source\VCL\AxCtrls.pas文件(这个文件中的代码有bug),拷贝到你的项目文件夹下,把这个文件添加为你项目的一部分(这样delphi就会应用你修改后的AxCtrls.pas)

2、找到AxCtrls.pas文件中的函数ParkingWindow,用下面的代码替换

function ParkingWindow: HWND;

var

TempClass: TWndClass;

ParkingName : String;

begin

Result := xParkingWindow;

//if Result <> 0 then Exit; //这行代码在delphi5和delphi6中好像不用注释掉

// fix Dax error : accessviolation (win2k, win xp)

ParkingName := 'DAXParkingWindow_' + Format('%p', [@ParkingWindowProc]);

FillChar(TempClass, sizeof(TempClass), 0);

if not GetClassInfo(HInstance, PChar(ParkingName), TempClass) then // fix Dax error : accessviolation (win2k, win xp)

begin

TempClass.hInstance := HInstance;

TempClass.lpfnWndProc := @ParkingWindowProc;

TempClass.lpszClassName := PChar(ParkingName); // fix Dax error : accessviolation (win2k, win xp)

if Windows.RegisterClass(TempClass) = 0 then

raise EOutOfResources.Create(SWindowClass);

end;

xParkingWindow := CreateWindowEx(WS_EX_TOOLWINDOW, TempClass.lpszClassName, nil,

WS_POPUP, GetSystemMetrics(SM_CXSCREEN) div 2,

GetSystemMetrics(SM_CYSCREEN) div 2, 0, 0, 0, 0, HInstance, nil);

SetWindowPos(xParkingWindow, 0, 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOREDRAW

or SWP_NOZORDER or SWP_SHOWWINDOW);

Result := xParkingWindow;

end;

3、编译项目即可

参考资料:

http://www.delphibbs.com/delphibbs/dispq.asp?lid=919005

http://blog.chinaunix.net/u/4831/showart_187926.html,这个文档说delphi7解决不了,其实是少注释了一行代码