Thread View: borland.public.cppbuilder.internet.web
8 messages
8 total messages
Started by Mitch McInelly
Fri, 11 Feb 2005 14:32
TCppWebBrower AutoFill functionality
Author: Mitch McInelly
Date: Fri, 11 Feb 2005 14:32
Date: Fri, 11 Feb 2005 14:32
19 lines
1846 bytes
1846 bytes
I'm trying to add a function to my app that mimics the Google toolbar AutoFill functionality - except on a much broader scale. I plan to map the fields of various 3rd party websites (of which I have no control) to my existing databases so that my users will only have to enter the information once. I've tried scraping the web page into a memo, changing the "value=" properties of the fields, and then sending back to the browser. This doesn't work because the document then looses site of where it came from (it thinks it's at about:blank) and the only way I can get back is to Navigate there - which looses my changes. I've tried implementing Adam's code but it doesn't appear to work for me. Has anyone been down this road? Even the tiniest crumb of advice on a starting point would be greatly appreciated. I plead ignorance.
Re: TCppWebBrower AutoFill functionality
Author: Hans Galema
Date: Fri, 11 Feb 2005 15:30
Date: Fri, 11 Feb 2005 15:30
23 lines
1738 bytes
1738 bytes
Mitch McInelly wrote: > I'm trying to add a function to my app that mimics the Google toolbar > AutoFill functionality > I've tried scraping the web page into a memo, changing the "value=" > properties of the fields, What have both things to do with each other ? > and then sending back to the browser. This > doesn't work because the document then looses site of where it came from (it > thinks it's at about:blank) and the only way I can get back is to Navigate > there - which looses my changes. You know that javascript can change 'values' ? > I've tried implementing Adam's code but it doesn't appear to work for me. Which code ? Adam's code ? Please explain why an autofill should change values. Hans.
Re: TCppWebBrower AutoFill functionality
Author: Mitch McInelly
Date: Fri, 11 Feb 2005 16:50
Date: Fri, 11 Feb 2005 16:50
112 lines
4564 bytes
4564 bytes
Hello Hans,
Thanks you so much for your response. I have lot's of desktop experience
but no web experience. I apologize for being a neophyte.
Maybe my assumptions are wrong. I am trying to insert a value into a field
on an existing web page. 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">
I realize that Google's Autofill doesn't do this as the HTML doesn't change
after the form is filled. I don't know how they are doing it. These are
not my web pages, they are application pages for insurance companies, so I
can't use Javascript to populate the pages - as I understand it.
Using Adam Vieweger/s article "How to post data using TCppWebBrowser in
C++Builder".
http://community.borland.com/article/0,1410,27519,00.html (which you have
referenced in this forum) results in the following code in my application:
void __fastcall TMain::WebPostData(TCppWebBrowser *CppWebBrowser, String
sURL, String sPostData)
{
BSTR bstrHeaders = NULL;
TVariant vFlags = {0}, vTargetFrameName={0}, vPostData={0}, vHeaders={0};
LPSAFEARRAY psa;
LPCTSTR cszPostData = sPostData.c_str();
UINT cElems = lstrlen(cszPostData);
LPSTR pPostData;
LPVARIANT pvPostData;
bstrHeaders = SysAllocString(L"Content-Type:
application/x-www-form-urlencodedrn");
if (!bstrHeaders){
Application->MessageBox("Could not allocate bstrHeaders", "Warning",
MB_OK | MB_ICONWARNING);
return;
}
V_VT(&vHeaders) = VT_BSTR;
V_BSTR(&vHeaders) = bstrHeaders;
pvPostData = vPostData;
if(pvPostData){
VariantInit(pvPostData);
psa = SafeArrayCreateVector(VT_UI1, 0, cElems);
if(!psa){
return;
}
SafeArrayAccessData(psa, (LPVOID*)&pPostData);
memcpy(pPostData, cszPostData, cElems);
SafeArrayUnaccessData(psa);
V_VT(pvPostData) = VT_ARRAY | VT_UI1;
V_ARRAY(pvPostData) = psa;
}
WebBrowser->Navigate2((TVariant)sURL, &vFlags, &vTargetFrameName,
&vPostData, &vHeaders);
}
which I am calling with:
WebPostData(myBrowser,"http://www.agencysoftware.com/demos.shtml","action=Submit&realname=Mitch");
This doesn't do anything but display the web page with blank fields. Even
if it did, I don't always want to push the Submit button - just populate the
fields for the user.
If you would be intersted in possibly working as a consultant for me on this
project, please email me directly at mitch@agencysoftware.com
Thank you for your time.
Mitch McInelly
"Hans Galema" <notused@notused.nl> wrote in message
news:420ccfcb@newsgroups.borland.com...
> Mitch McInelly wrote:
>> I'm trying to add a function to my app that mimics the Google toolbar
>> AutoFill functionality
>
>> I've tried scraping the web page into a memo, changing the "value="
>> properties of the fields,
>
> What have both things to do with each other ?
>
>> and then sending back to the browser. This doesn't work because the
>> document then looses site of where it came from (it thinks it's at
>> about:blank) and the only way I can get back is to Navigate there - which
>> looses my changes.
>
> You know that javascript can change 'values' ?
>
>> I've tried implementing Adam's code but it doesn't appear to work for me.
>
> Which code ? Adam's code ?
>
> Please explain why an autofill should change values.
>
> Hans.
Re: TCppWebBrower AutoFill functionality
Author: Remy Lebeau (TeamB)
Date: Fri, 11 Feb 2005 19:33
Date: Fri, 11 Feb 2005 19:33
15 lines
1504 bytes
1504 bytes
"Mitch McInelly" <mitch@agencysoftware.com> wrote in message news:420cc1f5@newsgroups.borland.com... > I've tried scraping the web page into a memo, changing the > "value=" properties of the fields, and then sending back to > the browser. Use the browser's DOM interfaces to query and update the values directly. Once the page is fully loaded, you can query the Document property for the IHTMLDocument2 interface and go from there. IHTMLDocument2 and related interfaces are documented at MSDN. Gambit
Re: TCppWebBrower AutoFill functionality
Author: 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
Re: TCppWebBrower AutoFill functionality
Author: Mitch McInelly
Date: Fri, 11 Feb 2005 21:37
Date: Fri, 11 Feb 2005 21:37
41 lines
2445 bytes
2445 bytes
Hi Gambit,
Thank you so much for your quick response! I implemented your code into my
app and it bombs with errors on three lines:
1) Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID)&Doc);
gives 'Could not find match for
IUnknown::QueryInterface(const_GUID,void *);' doesn't seem to like the
IID_IHTMLDocument2 parameter?
2) All->get_item(item, index, &Disp);
gives 'get_item is not a member of IHTMLElementCollection'
3) Disp->QueryInterface(IID_IHTMLInputTextElement,(LPVOID)&TextInput);
gives 'Could not find match for
IUnknown::QueryInterface(const_GUID,void *);'
Do you suppose that it's the placement of the headers in my source?
Mitch McInelly
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:420d079e@newsgroups.borland.com...
>
> "Mitch McInelly" <mitch@agencysoftware.com> wrote in message
> news:420cc1f5@newsgroups.borland.com...
>
>> I've tried scraping the web page into a memo, changing the
>> "value=" properties of the fields, and then sending back to
>> the browser.
>
> Use the browser's DOM interfaces to query and update the values directly.
> Once the page is fully loaded, you can query the Document property for the
> IHTMLDocument2 interface and go from there. IHTMLDocument2 and related
> interfaces are documented at MSDN.
>
>
> Gambit
>
>
Re: TCppWebBrower AutoFill functionality
Author: Remy Lebeau (TeamB)
Date: Fri, 11 Feb 2005 23:27
Date: Fri, 11 Feb 2005 23:27
32 lines
1866 bytes
1866 bytes
"Mitch McInelly" <mitch@agencysoftware.com> wrote in message
news:420d2623$1@newsgroups.borland.com...
> 1) Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID)&Doc);
> gives 'Could not find match for
IUnknown::QueryInterface(const_GUID,void *);'
Sorry, that was a typo on my part, I left out an asterik in the last
parameter:
Browser->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&Doc);
> 2) All->get_item(item, index, &Disp);
> gives 'get_item is not a member of IHTMLElementCollection'
Another typo, it should be this:
All->item(item, index, &Disp);
> 3) Disp->QueryInterface(IID_IHTMLInputTextElement,(LPVOID)&TextInput);
> gives 'Could not find match for
IUnknown::QueryInterface(const_GUID,void *);'
Same as the first error above.
> Do you suppose that it's the placement of the headers in my source?
No.
Gambit
Re: TCppWebBrower AutoFill functionality
Author: Mitch McInelly
Date: Sat, 12 Feb 2005 01:02
Date: Sat, 12 Feb 2005 01:02
51 lines
2596 bytes
2596 bytes
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!! Remy - Please send me your snail mail address to mitch@agencysoftware.com I would like to send you something. You are very nice for taking the time to consider my problem. Mitch McInelly "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:420d3e9b$1@newsgroups.borland.com... > > "Mitch McInelly" <mitch@agencysoftware.com> wrote in message > news:420d2623$1@newsgroups.borland.com... > >> 1) Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID)&Doc); >> gives 'Could not find match for > IUnknown::QueryInterface(const_GUID,void *);' > > Sorry, that was a typo on my part, I left out an asterik in the last > parameter: > > Browser->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&Doc); > >> 2) All->get_item(item, index, &Disp); >> gives 'get_item is not a member of IHTMLElementCollection' > > Another typo, it should be this: > > All->item(item, index, &Disp); > >> 3) Disp->QueryInterface(IID_IHTMLInputTextElement,(LPVOID)&TextInput); >> gives 'Could not find match for > IUnknown::QueryInterface(const_GUID,void *);' > > Same as the first error above. > >> Do you suppose that it's the placement of the headers in my source? > > No. > > > Gambit > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads