Article View: borland.public.cppbuilder.internet.web
Article #1417Re: TCppWebBrower AutoFill functionality
From: Remy Lebeau (TeamB)
Date: Fri, 11 Feb 2005 19:42
Date: Fri, 11 Feb 2005 19:42
94 lines
4060 bytes
4060 bytes
"Mitch McInelly" <mitch@agencysoftware.com> wrote in message
news:420ce2c9$1@newsgroups.borland.com...
> The only way I know to do this is by somehow changing the html from, say:
>
> <input class="frmfld" type="text" name="realname" size="40">
> to <input class="frmfld" type="text" name="realname" value="Mitch
McInelly"
> size="40">
#include <utilcls.h>
#include <mshtml.h>
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject* Sender,
LPDISPATCH pDisp, TVariant *URL)
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID)&Doc);
if( Doc )
{
TComInterface<IHTMLElementCollection> All;
Doc->get_all(&All);
if( All )
{
TVariant name = WideString("realname");
TVariant index = 0;
TComInterface<IDispatch> Disp;
All->get_item(name, index, &Disp);
if( Disp )
{
TComInterface<IHTMLInputTextElement> TextInput;
Disp->QueryInterface(IID_IHTMLInputTextElement,
(LPVOID)&TextInput);
if( TextInput )
TextInput->put_value(WideString("Mitch McInelly"));
}
}
}
}
You can generalize that code by looping through the All collection, querying
to see if each element is in your database:
#include <utilcls.h>
#include <mshtml.h>
void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject* Sender,
LPDISPATCH pDisp, TVariant *URL)
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID)&Doc);
if( Doc )
{
TComInterface<IHTMLElementCollection> All;
Doc->get_all(&All);
if( All )
{
long count = 0;
All->get_length(&count);
for(long idx = 0; idx < count; ++idx)
{
TVariant item = idx;
TVariant index = 0;
TComInterface<IDispatch> Disp;
All->get_item(item, index, &Disp);
if( Disp )
{
TComInterface<IHTMLInputTextElement> TextInput;
Disp->QueryInterface(IID_IHTMLInputTextElement,
(LPVOID)&TextInput);
if( TextInput )
{
WideString name;
TextInput->get_name(&name);
if( name is in the database )
TextInput->put_value(WideString(value from
database));
}
}
}
}
}
}
Gambit
Technical Details
Message-ID:
<420d09df$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newspeer2.se.telia.net!se.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!ltu.se!luth.se!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<420cc1f5@newsgroups.borland.com> <420ccfcb@newsgroups.borland.com> <420ce2c9$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,f1eac53c40f0896b X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <420cc1f5@newsgroups.borland.com> <420ccfcb@newsgroups.borland.com> <420ce2c9$1@newsgroups.borland.com> Subject: Re: TCppWebBrower AutoFill functionality Date: Fri, 11 Feb 2005 11:42:42 -0800 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <420d09df$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1108150751 68.69.17.41 (11 Feb 2005 11:39:11 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newspeer2.se.telia.net!se.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!ltu.se!luth.se!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail