🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.multi-tier
2 messages
2 total messages Started by Rob Whitehead Mon, 03 Dec 2001 12:31
My IAppServer function barfs using ScktSrvr
#373
Author: Rob Whitehead
Date: Mon, 03 Dec 2001 12:31
15 lines
1500 bytes
Hi,

I have added a function to my IAppServer implementation class, for returning
an unsigned long value

HRESULT GetMaxKey(BSTR TableName, BSTR ColumnName, unsigned_long* Key)

Calling this function using a TDCOMConnection works without problem, however
calling the same function using a TSocketConnection throws an exception
'Error creating variant array'.

Other functions are working ok, it is only this one that is causing a
problem, should I be using an unsigned long * or not?

Regards
Re: My IAppServer function barfs using ScktSrvr
#387
Author: John Graham
Date: Sat, 15 Dec 2001 15:20
101 lines
4167 bytes
Rob,

In your implementation class make the data type of the last parameter of your
GetMaxKey() method a pointer to variant (VARIANT*) and assign the Modifier as
in/out.  Have the call to this method in the client app. pass a pointer to
TVariant as the third parameter.

In the app. server construct a variant array using "VarArrayCreate()" and stuff
your value into it.
Then add the array to your TVariant parameter.

Here's a snippet showing how I get the results of function calls into a
TStringList, then stuff the
contents of the list into the TVariant:

STDMETHODIMP TRptSrvrRDMImpl::ImpacInit(TVariant *vLogtext, BSTR MethodName)
    {
        ( lots of stuff goes on here - function calls that add strings to the
DataStrings TStringList)


    Variant v = VarArrayCreate(OPENARRAY(int, (0, m_DataModule->DataStrings->
    Count -1)), varOleStr);

    for ( int i = 0; i < m_DataModule->DataStrings->Count; i++)
        {
        v.PutElement(WideString(m_DataModule->DataStrings->Strings[i], i);
        }

    *vLogText = v;

    return S_OK
}

Remember that a variant array can accept any data type.  In your client:

void __fastcall TImpacForm::CreateSpdBtnClk(TObject *Sender)
{
     vLogText = new TVariant();

     WideString wsMethodName;

     HRESULT hr;

stuff going on here...

     // call the App. Server method that initializes the process
     hr = DataMod->RptSrvrDisp->ImpacInit(vLogText, wsMethodName.Copy());

test hr - if it's S_OK, proceed

    Variant value;

 // we convert the pointer to type TVariant to a pointer to type variant and
  // dereference it into variant "value".  we now have a variant array and can
  // use the methods of the variant class to recover the individual element
  // values.
 value = *vLogText->operator VARIANT*();

  if ( value.IsArray() )
   {
     for ( int i = 0; i <= value.ArrayHighBound(1); i++ )
       {
     // each element of the variant array is itself a variant.  we know
          // these are AnsiStrings, so we use the AnsiString() operator to make
          // the conversion.
         OpsMemo->Lines->Add(value.GetElement(i).operator AnsiString());
        }

   OpsMemo->Lines->Add(" ");
   }

 else
   {
   OpsMemo->Lines->Add("Application Server Failed to Return an Array");
    }

Hope this helps.  I use nothing but socket connections and the variant type to
return data from my app. servers.  I've never figured out how to do it any other
way.

Regards,
John

Rob Whitehead wrote:

> Hi,
>
> I have added a function to my IAppServer implementation class, for returning
> an unsigned long value
>
> HRESULT GetMaxKey(BSTR TableName, BSTR ColumnName, unsigned_long* Key)
>
> Calling this function using a TDCOMConnection works without problem, however
> calling the same function using a TSocketConnection throws an exception
> 'Error creating variant array'.
>
> Other functions are working ok, it is only this one that is causing a
> problem, should I be using an unsigned long * or not?
>
> Regards
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