有人能把这段C++代码转成Delphi的吗? (100分)

B

base7

Unregistered / Unconfirmed
GUEST, unregistred user!
天,晕得不行
代码:
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
     VARIANT id, index;
     CComPtr<IDispatch> spDispatch;
     CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
     CComQIPtr<IHTMLElement, &IID_IHTMLElement> pElement;
     CComPtr<IHTMLElementCollection> pElementCol;
     CComPtr<IHTMLFormElement> pFormElement;
     CComPtr<IHTMLInputTextElement> pInputElement;

if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))
               pDoc2 = spDispatch;
                if(pDoc2!=NULL)
                {
                //    AfxMessageBox("IHTMLDocument2");
                                if (SUCCEEDED(pDoc2->get_forms(&pElementCol)))
            {
            //    AfxMessageBox("IHTMLElementCollection");
                long p=0;
                if(SUCCEEDED(pElementCol->get_length(&p)));
                 if(p!=0)
                 {   
                    // AfxMessageBox("1");
                     for(long i=0;i<=(p-1);i++)
                     {
                      V_VT(&id) = VT_I4;
                      V_I4(&id) = i;
                      V_VT(&index) = VT_I4;
                      V_I4(&index) = 0;
                      if(SUCCEEDED(pElementCol->item(id,index, &spDispatch)))
                     // AfxMessageBox("2");
                      if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLFormElement,(void**)&pFormElement)))
                       {
                          // AfxMessageBox("IHTMLFormElement");
                           long q=0;
                           if(SUCCEEDED(pFormElement->get_length(&q)));
                           for(long j=0;j<=(q-1);j++)
                           {
                            V_VT(&id) = VT_I4;
                            V_I4(&id) = j;
                            V_VT(&index) = VT_I4;
                            V_I4(&index) = 0;
                           if(SUCCEEDED(pFormElement->item(id,index, &spDispatch)))
                           if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLInputTextElement,(void**)&pInputElement)))
                           {
                           //AfxMessageBox("IHTMLInputTextElement");
                           CComBSTR value;
                           CComBSTR type;
                           pInputElement->get_type(&type);
                           CString strtype(type);
                           strtype.MakeUpper();
                           if (lstrcmpi(strtype, _T("TEXT")) == 0) 
                           {
                            pInputElement->get_value(&value);
                            CString strvalue(value);
                            AfxMessageBox(strvalue);
                           }
                           }
                           }
                       }
                     }
                 }
            }
 
C

Cowry

Unregistered / Unconfirmed
GUEST, unregistred user!
外头考来的,看着像:D
var
ShellWindow: IShellWindows;
nCount: integer;
spDisp: IDispatch;
i,j,X: integer;
vi: OleVariant;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
iELC : IHTMLElementCollection ;
S,S2 : string;
HtmlInputEle : IHTMLInputElement;
HtmlSelEle : IHTMLSelectElement;
begin
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;

for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
if spDisp = nil then continue;
spDisp.QueryInterface( iWebBrowser2, IE1 );
if IE1 <> nil then
begin
IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin

ielc:=idoc1.Get_all;

for j:=0 to ielc.length-1 do
begin
Application.ProcessMessages;
spDisp := ielc.item(J, 0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))then
with HtmlInputEle do
begin
S2:=Type_;
S2:=UpperCase(S2);
//我把所有的input都填上 try , checkbox 都打勾
if (StrComp(PChar(S2),'TEXT')=0) or (StrComp(PChar(S2),'PASSWORD')=0) then
value :='try' //S:=S+#9+Value
else if StrComp(PChar(S2),'CHECKBOX')=0 then
begin
checked := True;
end;
end;
if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement ,HtmlSelEle))then
with HtmlSelEle, Memo1.Lines do
begin
S:=S+#9+IntToStr(selectedIndex+1); //这个是获取数据了
end;
end; //END FOR
Memo2.Lines.Add(S);
exit;
end;
end;
end;
end;
 
B

base7

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 
顶部