我写了个ActiveX控件,在这个控件里,我通过调用CreateOleObject("excel.application")来控制Excel,但是这个控件无论在win32应用程序里或是浏览器里运行时,每次一执行这句("CreateOleObject")就出现内存冲突的错误(Access violation at address 049E74CC in module 'Sample.ocx'.Read of address 00000000)。我已经调用了CoInitialize了。我非常不解,是怎么回事呢?请高手赐教。
procedure TFacade.ExportToExcel;
var
_ExcelApp,_WorkBook,_WorkSheet: Variant;
begin
try
_ExcelApp := CreateOleObject('Excel.Application');
except
on e : Exception do
begin
Application.MessageBox(PChar(Message_NoExcel+e.Message), '', 32);
Exit;
end;
end;
end;