Article View: borland.public.cppbuilder.internet.web
Article #798Re: IHTMLSelectElement put_onchange syntax
From: Remy Lebeau (TeamB)
Date: Tue, 31 Jan 2006 18:46
Date: Tue, 31 Jan 2006 18:46
100 lines
3579 bytes
3579 bytes
"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:
<43dfb00a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43dfa1e5$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 From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <43dfa1e5$1@newsgroups.borland.com> Subject: Re: IHTMLSelectElement put_onchange syntax Date: Tue, 31 Jan 2006 10:46:53 -0800 Lines: 102 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: <43dfb00a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1138733066 68.69.17.41 (31 Jan 2006 10:44:26 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail