将Visual C ++代码转换为Borland C ++ Builder

问题描述 投票:0回答:1

我用Visual C ++编写了一个程序。但是现在我必须把我的代码放在一个用Borland C ++ Builder编写的程序中。我的表单上有一个WebBrowser项。在Visual C ++中,我将数据写入文本框,从文本框中获取数据,然后使用以下代码单击WebBrowser上的按钮:

写数据:

WebBrowser1->Document->GetElementById("okul_kod")->SetAttribute("value", TextBox2->Text);

获取数据:

textBox17->Text = WebBrowser1->Document->GetElementById("kay_cev")->GetAttribute("value");

按钮单击:

WebBrowser1->Document->GetElementById("panelden_kayit")->InvokeMember("click");

我尝试了很多东西,并在网上搜索,但我找不到如何将此代码转换为Borland C ++ Builder。

能告诉我一些线索或建议吗?

c++ visual-c++ webbrowser-control c++builder vcl
1个回答
1
投票

在C ++ Builder 6中,它的TCppWebBrowser VCL组件是Internet Explorer ActiveX控件的薄包装器。它的Document属性返回一个IDispatch,您可以使用它直接访问IE的原始DOM接口(而Visual C ++似乎已经为您更好地包装了这些接口)。

尝试这样的事情:

#include <mshtml.h>
#include <utilcls.h>

// helpers for interface reference counting
// could alternatively use TComInterface instead of DelphiInterface
typedef DelphiInterface<IHTMLDocument3> _di_IHTMLDocument3;
typedef DelphiInterface<IHTMLElement> _di_IHTMLElement;

...

// Write Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("okul_kod"), &elem));
if (elem) OleCheck(elem->setAttribute(WideString("value"), TVariant(Edit2->Text)));

// Get Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("kay_cev"), &elem));
TVariant value;
if (elem) OleCheck(elem->getAttribute(WideString("value"), 2, &value));
Edit17->Text = value;

//Button Click:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("panelden_kayit"), &elem));
if (elem) elem->click();
© www.soinside.com 2019 - 2024. All rights reserved.