Thread View: borland.public.cppbuilder.internet.web
3 messages
3 total messages
Started by melk
Wed, 23 Mar 2005 19:49
Active Server Object AND response->write???
Author: melk
Date: Wed, 23 Mar 2005 19:49
Date: Wed, 23 Mar 2005 19:49
54 lines
2192 bytes
2192 bytes
Hi !,
I'm trying to build a Active Sever Object with Borland 6 C++, I just
created a Method to write a text into my ASP using "response->write" of my
IResponse interface but it doesn't work... ?!?!
I olso tryed to use response->redirect and It works!!!
Is There someone who can help me??
this is the code:
THKS
H
----------------------------------------------------------------------------
------
IScriptingContext *m_scriptContext;
IResponse *rs;
CPP
----------------------------------------------------------------------------
------
STDMETHODIMP TWEBImpl::OnStartPage(LPUNKNOWN AScriptingContext)
{
HRESULT hr = E_FAIL;
try
{
IObjectContext* ObjectContext;
m_scriptContext = (IScriptingContext*)AScriptingContext;
m_scriptContext->get_Response((IResponse**)&rs);
hr = TASPObject::OnStartPage(AScriptingContext);
}
return hr;
}
STDMETHODIMP TWEBImpl::Method1()
{
tagVARIANT rr;
rr.bstrVal = (WideString)"Prova";
rs->Write(rr);
return S_OK;
}
ASP
----------------------------------------------------------------------------
------
<%
set xx = Server.CreateObject("OJB.WEB")
xx.Method1
set xx = nothing
%>
Re: Active Server Object AND response->write???
Author: Remy Lebeau (TeamB)
Date: Wed, 23 Mar 2005 20:24
Date: Wed, 23 Mar 2005 20:24
70 lines
2901 bytes
2901 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:4241c844@newsgroups.borland.com...
> I just created a Method to write a text into my ASP using
"response->write"
> of my IResponse interface but it doesn't work... ?!?!
That is because you are not using it properly.
> m_scriptContext = (IScriptingContext*)AScriptingContext;
> m_scriptContext->get_Response((IResponse**)&rs);
Why are you retreiving the IResponse interface manually? TASPObject already
does that for you, and exposes it via its Response property. You don't need
your own OnStartPage() implementation at all.
> tagVARIANT rr;
> rr.bstrVal = (WideString)"Prova";
>
> rs->Write(rr);
That code will not work for several reasons. You did not initialize the
VARIANT before filling it in. You did not set the VARIANT's vt member to
VT_BSTR to tell the VARIANT that it contains a BSTR. You are assigning a
temporary WideString that goes out of scope immediately thus leaving the
VARIANT pointing to invalid string memory. You did not clean up the VARIANT
after using it.
Use something more like the following code instead:
STDMETHODIMP TWEBImpl::Method1()
{
try
{
VARIANT rr;
VariantInit(&rr);
rr.bstrVal = WideString("Prova").Detach();
rr.vt = VT_BSTR;
TASPObject::Response->Write(rr);
VariantClear(&rr);
}
catch(const Exception &e)
{
return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
}
return S_OK;
}
Which can then be simplied to the following:
#include <utilcls.h>
STDMETHODIMP TWEBImpl::Method1()
{
try
{
TVariant rr = WideString("Prova");
TASPObject::Response->Write(rr);
}
catch(const Exception &e)
{
return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
}
return S_OK;
}
Gambit
Re: Active Server Object AND response->write???
Author: melk
Date: Wed, 23 Mar 2005 20:45
Date: Wed, 23 Mar 2005 20:45
85 lines
3258 bytes
3258 bytes
I just try and It works...
THANKYOU VERY MUCH!!
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> ha scritto nel messaggio
news:4241d051@newsgroups.borland.com...
>
> "melk" <NOSPAMi_melk@libero.it> wrote in message
> news:4241c844@newsgroups.borland.com...
>
> > I just created a Method to write a text into my ASP using
> "response->write"
> > of my IResponse interface but it doesn't work... ?!?!
>
> That is because you are not using it properly.
>
> > m_scriptContext = (IScriptingContext*)AScriptingContext;
> > m_scriptContext->get_Response((IResponse**)&rs);
>
> Why are you retreiving the IResponse interface manually? TASPObject
already
> does that for you, and exposes it via its Response property. You don't
need
> your own OnStartPage() implementation at all.
>
> > tagVARIANT rr;
> > rr.bstrVal = (WideString)"Prova";
> >
> > rs->Write(rr);
>
> That code will not work for several reasons. You did not initialize the
> VARIANT before filling it in. You did not set the VARIANT's vt member to
> VT_BSTR to tell the VARIANT that it contains a BSTR. You are assigning a
> temporary WideString that goes out of scope immediately thus leaving the
> VARIANT pointing to invalid string memory. You did not clean up the
VARIANT
> after using it.
>
> Use something more like the following code instead:
>
> STDMETHODIMP TWEBImpl::Method1()
> {
> try
> {
> VARIANT rr;
> VariantInit(&rr);
> rr.bstrVal = WideString("Prova").Detach();
> rr.vt = VT_BSTR;
> TASPObject::Response->Write(rr);
> VariantClear(&rr);
> }
> catch(const Exception &e)
> {
> return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
> }
> return S_OK;
> }
>
>
> Which can then be simplied to the following:
>
> #include <utilcls.h>
>
> STDMETHODIMP TWEBImpl::Method1()
> {
> try
> {
> TVariant rr = WideString("Prova");
> TASPObject::Response->Write(rr);
> }
> catch(const Exception &e)
> {
> return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
> }
> return S_OK;
> }
>
>
> 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