Board index » cppbuilder » ADODB.Stream objects and Variants

ADODB.Stream objects and Variants


2005-09-16 07:00:58 PM
cppbuilder103
Hi all,
I'm working on CBuilder 5 without ADO controls, so I'm currently using Variants to access ADO. How can I get the following code (or something like it) to work?
void putStream (TMemoryStream *memStream) {
Variant stream = CreateOleObject("ADODB.Stream");
stream.OleProcedure("Open");
stream.OleProcedure("Write", memStream);
}
I know the above code doesn't appear to do anything, but I've got code I've left out which then goes on to do something with the stream Variant.
Thanks all,
Russ
Russell Allen
 
 

Re:ADODB.Stream objects and Variants

You can:
- wrap stream using TOleStream (ADODB.Stream implements IStream);
- wrap your memStream with TStreamAdapter and use it instead of ADODB.Stream
(when you pass stream, pass Variant of type IUnknown and value should have
interface that can be queried for IStream, IStream is implemented in
TStreamAdapter).
//------------------------------------------
Regards,
Vassiliev V. V.
www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Russell Allen" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях
следующе? news:432aa5ea$ XXXX@XXXXX.COM ...
Quote

Hi all,

I'm working on CBuilder 5 without ADO controls, so I'm currently using
Variants to access ADO. How can I get the following code (or something
like it) to work?

void putStream (TMemoryStream *memStream) {
Variant stream = CreateOleObject("ADODB.Stream");
stream.OleProcedure("Open");
stream.OleProcedure("Write", memStream);
}

I know the above code doesn't appear to do anything, but I've got code
I've left out which then goes on to do something with the stream Variant.

Thanks all,

Russ
Russell Allen
 

Re:ADODB.Stream objects and Variants

Import the ADO type library and include the resulting import file, i.e.
#include "AdoDb_TLB.H"
Then you can do this:
void putStream (TMemoryStream *memStream)
{
StreamPtr pStream = CoStream::Create();
OLECHECK(pStream->Open( {appropriate open parameters} ));
memStream->Seek(0, soFromBeginning);
bool FReleaseStream = true;
TStreamAdapter *sa = new TStreamAdapter(memStream, soReference);
if(!sa)
throw Exception("Could not create Stream interface");
try
{
IUnknown* iunk = NULL;
try
{
OLECHECK(sa->QueryInterface(IID_IUnknown, (LPVOID*)&iunk));
if(iunk == NULL)
throw Exception("Stream interface does not implement the IUnknown
interface");
TVariant v = iunk;
OLECHECK2(pStream->Write(v));
}
__finally
{
if(iunk)
{
FReleaseStream = false;
iunk->Release();
}
}
}
__finally
{
if(FReleaseStream && sa)
delete sa;
}
}
Mark
 

{smallsort}

Re:ADODB.Stream objects and Variants

You can use
TVariant v = iunk;
instead of pStream and pass it to ADO. This will remove a need to have
second stream.
//------------------------------------------
Regards,
Vassiliev V. V.
www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Mark Guerrieri" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях
следующе? news:432b48dd$ XXXX@XXXXX.COM ...
Quote
Import the ADO type library and include the resulting import file, i.e.

#include "AdoDb_TLB.H"

Then you can do this:

void putStream (TMemoryStream *memStream)
{
StreamPtr pStream = CoStream::Create();
OLECHECK(pStream->Open( {appropriate open parameters} ));

memStream->Seek(0, soFromBeginning);
bool FReleaseStream = true;
TStreamAdapter *sa = new TStreamAdapter(memStream, soReference);
if(!sa)
throw Exception("Could not create Stream interface");
try
{
IUnknown* iunk = NULL;
try
{
OLECHECK(sa->QueryInterface(IID_IUnknown, (LPVOID*)&iunk));
if(iunk == NULL)
throw Exception("Stream interface does not implement the IUnknown
interface");

TVariant v = iunk;

OLECHECK2(pStream->Write(v));
}
__finally
{
if(iunk)
{
FReleaseStream = false;
iunk->Release();
}
}
}
__finally
{
if(FReleaseStream && sa)
delete sa;
}
}


Mark


 

Re:ADODB.Stream objects and Variants

Thanks guys,
This looks like exactly what I was after! Very much appreciated. :)
Russ
"Viatcheslav V. Vassiliev" < XXXX@XXXXX.COM >wrote:
Quote
You can use

TVariant v = iunk;

instead of pStream and pass it to ADO. This will remove a need to have
second stream.

//------------------------------------------
Regards,
Vassiliev V. V.
www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Mark Guerrieri" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях
следующе? news:432b48dd$ XXXX@XXXXX.COM ...
>Import the ADO type library and include the resulting import file, i.e.
>
>#include "AdoDb_TLB.H"
>
>Then you can do this:
>
>void putStream (TMemoryStream *memStream)
>{
>StreamPtr pStream = CoStream::Create();
>OLECHECK(pStream->Open( {appropriate open parameters} ));
>
>memStream->Seek(0, soFromBeginning);
>bool FReleaseStream = true;
>TStreamAdapter *sa = new TStreamAdapter(memStream, soReference);
>if(!sa)
>throw Exception("Could not create Stream interface");
>try
>{
>IUnknown* iunk = NULL;
>try
>{
>OLECHECK(sa->QueryInterface(IID_IUnknown, (LPVOID*)&iunk));
>if(iunk == NULL)
>throw Exception("Stream interface does not implement the IUnknown
>interface");
>
>TVariant v = iunk;
>
>OLECHECK2(pStream->Write(v));
>}
>__finally
>{
>if(iunk)
>{
>FReleaseStream = false;
>iunk->Release();
>}
>}
>}
>__finally
>{
>if(FReleaseStream && sa)
>delete sa;
>}
>}
>
>
>Mark
>
>