 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
melk Guest
|
Posted: Wed Mar 23, 2005 7:49 pm Post subject: Active Server Object AND response->write??? |
|
|
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
%>
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Mar 23, 2005 8:24 pm Post subject: Re: Active Server Object AND response->write??? |
|
|
"melk" <NOSPAMi_melk (AT) libero (DOT) it> wrote
| Quote: | 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.
| Quote: | 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.
| Quote: | 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
|
|
| Back to top |
|
 |
melk Guest
|
Posted: Wed Mar 23, 2005 8:45 pm Post subject: Re: Active Server Object AND response->write??? |
|
|
I just try and It works...
THANKYOU VERY MUCH!!
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> ha scritto nel messaggio
news:4241d051 (AT) newsgroups (DOT) borland.com...
| Quote: |
"melk" <NOSPAMi_melk (AT) libero (DOT) it> wrote in message
news:4241c844 (AT) newsgroups (DOT) 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
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|