F
fjx99
Unregistered / Unconfirmed
GUEST, unregistred user!
把Delphi的代码翻译为C++Builder6后,调试状态会弹出CPU窗口,并且事件响应不起作用。
//------Delphi代码--------------------------------------------
uses Excel2000;
procedure TForm1.ExcelWorkbook1SheetBeforeDoubleClick(Sender: TObject;
var Sh, Target, Cancel: OleVariant);
begin
ShowMessage('double click');
PByte(TVarData(Cancel).VPointer)^ := $ff;
end;
procedure TForm1.ExcelWorkbook1SheetBeforeRightClick(Sender: TObject;
var Sh, Target, Cancel: OleVariant);
begin
ShowMessage('right click');
PByte(TVarData(Cancel).VPointer)^ := $ff;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
myWorkbook:TExcelWorkbook;
IWorkbook:_Workbook;
begin
OleContainer1.CreateObjectFromFile( 'c:/aaa.xls',true);
OleContainer1.DoVerb(ovShow);
(IDispatch(OleContainer1.OleObject)).QueryInterface(IID__Workbook, IWorkbook);
myWorkbook := TExcelWorkbook.Create(OleContainer1);
myWorkbook.ConnectTo(IWorkbook);
myWorkbook.OnSheetBeforeDoubleClick := ExcelWorkbook1SheetBeforeDoubleClick;
myWorkbook.OnSheetBeforeRightClick := ExcelWorkbook1SheetBeforeRightClick;
end;
//------------------------------------------------------------
//------翻译后的代码:弹出CPU窗口,事件响应不起作用-----------
void __fastcall TForm1::ExcelWorkbook1SheetBeforeDoubleClick(TObject *Sender, LPDISPATCH Sh, Range *Target, VARIANT_BOOL *Cancel)
{
ShowMessage("double click");
*Cancel = 0xff;
}
void __fastcall TForm1::ExcelWorkbook1SheetBeforeRightClick(TObject *Sender, LPDISPATCH Sh, Range *Target, VARIANT_BOOL *Cancel)
{
ShowMessage("right click");
*Cancel = 0xff;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OleContainer1->CreateObjectFromFile("c://aaa.xls",true);
OleContainer1->DoVerb(ovPrimary);
_WorkbookPtr wbPtr;
IDispatch* id = OleContainer1->OleObject;
HRESULT hr = id->QueryInterface(IID__Workbook, (void**)&wbPtr);
OleCheck(hr);
TExcelWorkbook *myWorkbook = new TExcelWorkbook(Application);
myWorkbook->ConnectTo(wbPtr);
myWorkbook->OnSheetBeforeDoubleClick = ExcelWorkbook1SheetBeforeDoubleClick;
myWorkbook->OnSheetBeforeRightClick = ExcelWorkbook1SheetBeforeRightClick;
/*
设置了OnSheetBeforeDoubleClick后,双击单元格,会弹出CPU窗口,指令停止在ret上,事件响应不起作用。
myWorkbook应该是正确的,因为下面的代码可以运行。直接扔TExcelApplication、TExcelWorkbook到窗口上,然后连接到Excel,OnSheetBeforeDoubleClick事件也是弹出CPU窗口。
_WorksheetPtr sheetPtr = myWorkbook->Worksheets->get_Item(TVariant("Sheet1"));
RangePtr changeRange = sheetPtr->get_Range(TVariant("A2"), TVariant("A2"));
changeRange = changeRange->get_Cells()->get_Item(TVariant("A2"), TVariant("A2"));
changeRange->set_Value(TVariant("New_Data"));
*/
}
//------Delphi代码--------------------------------------------
uses Excel2000;
procedure TForm1.ExcelWorkbook1SheetBeforeDoubleClick(Sender: TObject;
var Sh, Target, Cancel: OleVariant);
begin
ShowMessage('double click');
PByte(TVarData(Cancel).VPointer)^ := $ff;
end;
procedure TForm1.ExcelWorkbook1SheetBeforeRightClick(Sender: TObject;
var Sh, Target, Cancel: OleVariant);
begin
ShowMessage('right click');
PByte(TVarData(Cancel).VPointer)^ := $ff;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
myWorkbook:TExcelWorkbook;
IWorkbook:_Workbook;
begin
OleContainer1.CreateObjectFromFile( 'c:/aaa.xls',true);
OleContainer1.DoVerb(ovShow);
(IDispatch(OleContainer1.OleObject)).QueryInterface(IID__Workbook, IWorkbook);
myWorkbook := TExcelWorkbook.Create(OleContainer1);
myWorkbook.ConnectTo(IWorkbook);
myWorkbook.OnSheetBeforeDoubleClick := ExcelWorkbook1SheetBeforeDoubleClick;
myWorkbook.OnSheetBeforeRightClick := ExcelWorkbook1SheetBeforeRightClick;
end;
//------------------------------------------------------------
//------翻译后的代码:弹出CPU窗口,事件响应不起作用-----------
void __fastcall TForm1::ExcelWorkbook1SheetBeforeDoubleClick(TObject *Sender, LPDISPATCH Sh, Range *Target, VARIANT_BOOL *Cancel)
{
ShowMessage("double click");
*Cancel = 0xff;
}
void __fastcall TForm1::ExcelWorkbook1SheetBeforeRightClick(TObject *Sender, LPDISPATCH Sh, Range *Target, VARIANT_BOOL *Cancel)
{
ShowMessage("right click");
*Cancel = 0xff;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OleContainer1->CreateObjectFromFile("c://aaa.xls",true);
OleContainer1->DoVerb(ovPrimary);
_WorkbookPtr wbPtr;
IDispatch* id = OleContainer1->OleObject;
HRESULT hr = id->QueryInterface(IID__Workbook, (void**)&wbPtr);
OleCheck(hr);
TExcelWorkbook *myWorkbook = new TExcelWorkbook(Application);
myWorkbook->ConnectTo(wbPtr);
myWorkbook->OnSheetBeforeDoubleClick = ExcelWorkbook1SheetBeforeDoubleClick;
myWorkbook->OnSheetBeforeRightClick = ExcelWorkbook1SheetBeforeRightClick;
/*
设置了OnSheetBeforeDoubleClick后,双击单元格,会弹出CPU窗口,指令停止在ret上,事件响应不起作用。
myWorkbook应该是正确的,因为下面的代码可以运行。直接扔TExcelApplication、TExcelWorkbook到窗口上,然后连接到Excel,OnSheetBeforeDoubleClick事件也是弹出CPU窗口。
_WorksheetPtr sheetPtr = myWorkbook->Worksheets->get_Item(TVariant("Sheet1"));
RangePtr changeRange = sheetPtr->get_Range(TVariant("A2"), TVariant("A2"));
changeRange = changeRange->get_Cells()->get_Item(TVariant("A2"), TVariant("A2"));
changeRange->set_Value(TVariant("New_Data"));
*/
}