A work around for Delphi 2007/2009 with Windows 7 64 bit

I just installed Windows 7, 64 bit edition so that I could code and test against this new operating system.  Visual Studio 2008 installed and ran without any incident, but I hit a snag with Delphi 2007.  Delphi 2007 installed just fine, but it would die when you ended a debugging session.  An assert error would get thrown and after you cleared the dialog, Delphi would be terminated.
The error was thrown by bordbk105N.dll and had the following text:

Assertion failure: “(!”SetThreadContext failed”)”
in ..\win32src\thread32.cpp at line 412
Continue execution?

That was followed by a “Yes/No” set of buttons.  It didn’t matter which choice you made, it was pretty much game over for Delphi at this point. After getting this happen 3 times in a row (even with Delphi launched with “Run As Administrator”), I decided to check the Internet and see if this was unique to me and if there was a fix.
I checked Google and found a few hits.  One of them led me to a blog written by Olaf Monien, a German developer with close ties to the Delphi R & D department.  His post, “Delphi 2009 / Windows 7 / 64 bit Debugger Crash Workaround”, described the issue in great detail.  Apparently an incorrect call is being made to the SetThreadContext API call.  The debugger dll has an assert call based on the return value SetThreadContext().  It’s odd that production code went out with asserts enable, that’s usually used during testing.  Some people traced through the debugger code and found that if a single byte is changed in the dll, you could get by this error.  This byte changes the logic so it ignores the return code from SetThreadContext() and never hits the assert code.  You can read about how they came up with that idea here.
An enterprising programmer named “LordByte” wrote a handy little utility that will patch the debugger dll for both Delphi 2007 and Delphi 2009.  Olaf is hosting the patch tool on his blog and This file found a permanent home at Embarcadero and you can download it from Delphi_2007_2009_WOW64_Debugger_Fix.zip.  This works but you now have the added risk of actual errors being returned from that call to SetThreadContext() being ignored.  Since the alternative is an unusable Delphi, it’s a risk I’m going to have to take.

[Edited April 22nd, 2013]
While I no longer use Delphi, I hate to see a broken link.  I updated the download link for the debugger patch to it’s current home at Embarcadero.

12 thoughts on “A work around for Delphi 2007/2009 with Windows 7 64 bit”

  1. Hey thanks a lot! I actually just got my super-workstation Windows 2008 R2 up and running and this is one of the few wacky things that annoyed me!

  2. Thank you so much!!
    It only started recently for me, and only in some of my projects, but it was really annoying having to build and then run through Explorer every time to avoid the crash. Horribly inefficient…

  3. Thanks loads! I had to update a few Delphi 2007 projects and this was driving me nuts!

    The projects are not worth porting to Delphi 2010, but it would be nice if we could still support them with 2007. I have to admit for any new development we have had to dump Delphi all together. After we got screwed with the change to Prism we decided that it just was not worth it.

  4. David, I updated the link to reflect the new location (thank you Internet Search Engines!). I no longer use Delphi and have not verified that it will still work.

Comments are closed.