Article View: borland.public.cppbuilder.internet.web
Article #799Re: IHTMLSelectElement put_onchange syntax
From: Mitch McInelly
Date: Tue, 31 Jan 2006 22:52
Date: Tue, 31 Jan 2006 22:52
149 lines
4806 bytes
4806 bytes
When I implement...
TVariant event;
Input->get_onchange(&event);
if( V_VT(&event) == VT_DISPATCH )
{
IDispatch *pEventDisp = V_DISPATCH(&event);
if( pEventDisp )
{
DISPPARAMS Params = {0};
TVariant Result;
and get to the last line...
> pEventDisp->Invoke(DISPID_VALUE, IID_NULL,
> LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &Params, &Result, NULL, NULL)
I get an arror that says
'An error has occured in the script on this page.
Line: 127
Char: 3
Error: 'options' is null or not an object
Code: 0
URL: blah blah blah
Do you want to continue running scripts?
Do I need to define the parameters that we are sending?
Alas I am not good enough at DOM to ' configure pEventObj as needed ...'
in your second example.
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:43dfb00a$1@newsgroups.borland.com...
>
> "Mitch McInelly" <mitch@agencysoftware.com> wrote in message
> news:43dfa1e5$1@newsgroups.borland.com...
>
>> IDispatch *ppvdispOption;
>> IHTMLOptionElement *ppvOption;
>
> You should wrap those in TComInterface so that you do not leak them.
>
>> BSTR *pszOptText;
>
> Use a WideString instead so that you do not leak it.
>
>> if(UpperCase(Name)==UpperCase(AnsiString(Field)))
>
> Use AnsiSameText() instead:
>
> if( AnsiSameText(name, Field) )
>
> Or, if you are using BCB 6+, then use WideSameText():
>
> if( WideSameText(name, Field) )
>
>> Trim(TValue);
>
> That has no effect. Trim() does not alter the string that is passed to
> it.
> It returns a new AnsiString instead:
>
> AnsiString TValue = value;
> TValue = Trim(TValue);
>
> Or:
>
> AnsiString TValue = AnsiString(value).Trim();
>
> Alternatively, if you are using BCB v6+, then Trim() has an overloaded
> version for WideString:
>
> WideString TValue = Trim(value);
>
>> if(UpperCase(TValue)==UpperCase(Value))
>
> Again, use AnsiSameText() (or WideSameText()):
>
> if( AnsiSameText(TValue, Value) )
>
>> TComInterface<IHTMLSelectElement> Input;
>> Disp->QueryInterface(IID_IHTMLSelectElement,(LPVOID*)&Input);
>> Input->put_onchange(index);
>
> That will not work. In order to trigger the event, you have to RETRIEVE
> the
> event handler and then call it directly, but you are trying to ASSIGN the
> handler instead (and not properly at that). Use this instead:
>
> TVariant event;
> Input->get_onchange(&event);
> if( V_VT(&event) == VT_DISPATCH )
> {
> IDispatch *pEventDisp = V_DISPATCH(&event);
> if( pEventDisp )
> {
> DISPPARAMS Params = {0};
> TVariant Result;
> pEventDisp->Invoke(DISPID_VALUE, IID_NULL,
> LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &Params, &Result, NULL, NULL)
> }
> }
>
> Alternatively, use the IHTMLElement3::fireEvent() method instead:
>
> TComInterface<IHTMLDocument4> Doc4 = Doc;
> TComInterface<IHTMLElement3> Element = Input;
>
> if( (Doc4) && (Element) )
> {
> IHTMLEventObj *pEventObj = NULL;
> Doc4->createEventObject(NULL, &pEventObj);
> if( pEventObj )
> {
> TVariant Event;
> VARIANT_BOOL Canceled = VARIANT_FALSE;
>
> V_VT(&Event) = VT_DISPATCH;
> V_DISPATCH(&Event) = pEventObj;
> // configure pEventObj as needed ...
>
> Element->fireEvent(WideString("onchange"), &Event, &Canceled);
> }
> }
> else
> {
> // use the code further above ...
> }
>
>> This code does not appear to fire the onchange event.
>
> Of course not. You are not even calling the event handler at all.
>
>
> Gambit
>
>
Technical Details
Message-ID:
<43dfeb33$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<43dfa1e5$1@newsgroups.borland.com> <43dfb00a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,4307e96a2fc07463 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Mitch McInelly" <mitch@agencysoftware.com> From: "Mitch McInelly" <mitch@agencysoftware.com> Newsgroups: borland.public.cppbuilder.internet.web References: <43dfa1e5$1@newsgroups.borland.com> <43dfb00a$1@newsgroups.borland.com> Subject: Re: IHTMLSelectElement put_onchange syntax Date: Tue, 31 Jan 2006 14:52:44 -0800 Lines: 151 Organization: Agency Software, Inc. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 207.88.115.45 Message-ID: <43dfeb33$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1138748211 207.88.115.45 (31 Jan 2006 14:56:51 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail