ActiveX Dll中触发输入框中的on_change事件问题!!!(100分)

  • 主题发起人 主题发起人 cgfhz
  • 开始时间 开始时间
C

cgfhz

Unregistered / Unconfirmed
GUEST, unregistred user!
在简单的页面中触发多个on_change事件没有问题,如果on_change需要取数据库信息的时候,只能触发第一个on_change事件,后面都无效!
请高手指教,还有网上有用fireEvent处理事件的,不知道可行否?
代码如下:
procedure ExtractLinks(WebBrowser: IWebBrowser2);

var
vFrame, ret: OleVariant;

ilFrameIndex, ilFramesCount: integer;

pDoc, HTMLDocument: IHTMLDocument2;

pWindow: IHTMLWindow2;

pFrames: IHTMLFramesCollection2;

spdisp:idispatch;

HtmlInputEle: IHTMLInputElement;

ev: IDispatch;

vi, vi2, vr: OleVariant;

dispparamsNoArgs: DISPPARAMS;

begin

if(SUCCEEDED(WebBrowser.Document.QueryInterface(
IID_IHTMLDocument2, HTMLDocument))) then

begin

pFrames:=(HTMLDocument.get_frames as IHTMLFramesCollection2);

ilFramesCount := pFrames.get_length;


TVariantArg(vFrame).vt := VT_UINT;

for ilFrameIndex := 1 to ilFramesCount - 1do

begin

TVariantArg(vFrame).lVal := ilFrameIndex;

spDisp := pFrames.item(vFrame);

if (SUCCEEDED(spDisp.QueryInterface(IID_IHTMLWindow2, pWindow))) then

begin

pDoc := pWindow.get_document;

if pDoc.title = '数据录入' then

begin

HtmlInputEle:=(pDoc.all.item('test1',0) as IHTMLInputElement);

if HtmlInputEle <> nil then

begin

HtmlInputEle.select;

HtmlInputEle.value :='111';

vi2 := HtmlInputEle.get_onchange;

ev := IDispatch(vi2);

dispparamsNoArgs.rgvarg := nil;

dispparamsNoArgs.rgdispidNamedArgs := nil;

dispparamsNoArgs.cArgs := 0;

dispparamsNoArgs.cNamedArgs := 0;

ev.Invoke(
DISPID_VALUE,
GUID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
dispparamsNoArgs,
@vr,
nil,
nil);

end;


HtmlInputEle:=(pDoc.all.item('test2',0) as IHTMLInputElement);

if HtmlInputEle <> nil then

begin

HtmlInputEle.select;

HtmlInputEle.value :='222';

vi2 := HtmlInputEle.get_onchange;

ev := IDispatch(vi2);

dispparamsNoArgs.rgvarg := nil;

dispparamsNoArgs.rgdispidNamedArgs := nil;

dispparamsNoArgs.cArgs := 0;

dispparamsNoArgs.cNamedArgs := 0;

ev.Invoke(
DISPID_VALUE,
GUID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
dispparamsNoArgs,
@vr,
nil,
nil);

end;


end;


end;


end;


end;


end;
 
高手,版主快快献身,帮小弟一次~
 
CSDN上没人回答,这里也没人回答
自己用fireevent重新写了个,测试基本通过了
procedure ExtractLinks2(WebBrowser: IWebBrowser2);
var
hdoc4: IHTMLDocument4;
heo: IHTMLEventObj;
hdoc2: IHTMLDocument2;
hec: IHTMLElementCollection;
disp: IDispatch;
he3: IHTMLElement3;
Caceled: WordBool;
ret, tmpvi: OleVariant;
begin

if(SUCCEEDED(WebBrowser.Document.QueryInterface(
IID_IHTMLDocument4, hdoc4))) then

begin

TVariantArg(ret).vt := VT_UINT;
TVariantArg(ret).lVal := 0;
heo := hdoc4.CreateEventObject(ret);

if(SUCCEEDED(WebBrowser.Document.QueryInterface(
IID_IHTMLDocument2, hdoc2))) then

begin

hec := hdoc2.get_all;
disp := hec.item('txtjjhy', 0);
he3 := disp as IHTMLElement3;

//用IHTMLElement3的fireEvent调用onchange
tmpvi := heo;
Caceled := he3.fireEvent('onchange',tmpvi);
end;

end;

end;
 
随便来个人顶下,到时我好散分
 
后退
顶部