TWebBrowser组件,实现“Copy”功能时出错,请
Debugger Exception Notification
---------------------------
Project ebuy.exe raised exception class EOleException with message ''试图吊销一个未注册的拖放目标''. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
我的代码:
procedure TfrmMain.mnuCopyClick(Sender: TObject);
var
ActiveWebBrowser: TWebBrowser;
begin
ActiveWebBrowser:=GetActiveWebBrowser();
if ActiveWebBrowser=nil then
exit;
if(ActiveWebBrowser.QueryStatusWB(OLECMDID_COPY)=(OLECMDF_ENABLED or OLECMDF_SUPPORTED)) then
ActiveWebBrowser.ExecWB(OLECMDID_COPY,OLECMDEXECOPT_DODEFAULT,EmptyParam,EmptyParam);
end;
其中GetActiveWebBrowser()是取得当前活动窗体的TWebBrowser控件,应当没有问题,因为用同样的办法实现“保存”、“打印”均没有出现问题。
2楼: procedure TfrmMain.mnuCopyClick(Sender: TObject);
var
ActiveWebBrowser: TWebBrowser;
begin
ActiveWebBrowser:=GetActiveWebBrowser();
if ActiveWebBrowser=nil then
exit;
OleInitialize(nil);
if(ActiveWebBrowser.QueryStatusWB(OLECMDID_COPY)=(OLECMDF_ENABLED or OLECMDF_SUPPORTED)) then
ActiveWebBrowser.ExecWB(OLECMDID_COPY,OLECMDEXECOPT_DODEFAULT,EmptyParam,EmptyParam);
OleUninitialize;
end;
或
initialization
OleInitialize(nil);
finalization
try
OleUninitialize;
except
end;
这几句话放在主窗口所有语句之后,“end.”之前。 如java进销存管理系统
3楼: 请问为什么用同样的办法实现“保存”、“打印”均没有出现问题?
4楼: [Error] Unit1.pas(595): Undeclared identifier: ''OleInitialize''
[Error] Unit1.pas(598): Undeclared identifier: ''OleUnInitialize''
[Fatal Error] ebuy.dpr(11): Could not compile used unit ''Unit1.pas''
5楼: 明白了,加上Use ActiveX就可以了。但是为什么这么怪呢
6楼: 明白了:
TWebBrowser.ExecWB can generate the error "Trying to revoke a drop taget that has not been registered" under 2 different conditions:
1 TWebBrowser is not yet ready to accept the command. For following may generate this error:
Navigate(''e:\pictures\1.jpg'');
ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMTUSER);
To resolve the problem use QueryStatusWB and wait for it to return OLECMDF_SUPPORTED+OLECMDF_ENABLED. Below is an exmaple the fixes the problem:\
Navigate(''e:\pictures\picture1.jpg'');
while QueryStatusWB( OLECMDID_PRINT) <> OLECMDF_SUPPORTED + OLECMDF_ENABLED do
Forms.Application.ProcessMessages;
ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER);
2. Even though you user QueryStatusWB, Copy and Paste may still fail. Add the following to the end of your unit to resolve the problem:
initialization
OleInitialize(nil);
finalization
OleUninitialize;
看来Borland也没有什么合理的解释……
企业管理软件版7楼: 接受答案了.