After migrating an application from C++ Builder 4 to C++builder 6, the excel COM automation started to crash with error EAccessViolation at address 00000800 when calling the Variant.OlePropertySet(), OlePropertyGet() or OleFunction() methods, as in the following code :
Variant xlApp = Variant::CreateObject(“Excel.Application”);
xlApp.OlePropertySet(“Visible”, true); // causes the EAccessViolation
Variant workbooks = xlApp.OlePropertyGet(“Workbooks”);
Variant currentWorkbook ClasseurCourant = workbooks.OleFunction(“Open”, L”C:\\MyExcelFile.xls”);
This code was working fine with Builder 4, it was also working fine when used in a brand new application, but it always crashed in the converted app. Given that many developers reported the same error, with no known fix, and that one couldn’t expect support for a 12 years old IDE, I eventually fixed the issue by bypassing the Borland Wrappers and using directly COM.