🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.multi-tier
Article #387

Re: My IAppServer function barfs using ScktSrvr

#387
From: 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
Technical Details
Message-ID: <3C1B6A49.C0A3D0E3@salts.navy.mil>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-out.visi.com!hermes.visi.com!out.nntp.be!propagator-SanJose!in.nntp.be!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3c0b70e0_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcd2b,c12d01b115d1ee84
X-Google-Attributes: gidfcd2b,public
X-Google-Thread: f6386,c12d01b115d1ee84
X-Google-Attributes: gidf6386,public
X-Google-ArrivalTime: 2001-12-15 07:21:36 PST
Message-ID: <3C1B6A49.C0A3D0E3@salts.navy.mil>
Date: Sat, 15 Dec 2001 10:20:41 -0500
From: John Graham <jgraham@salts.navy.mil>
X-Mailer: Mozilla 4.78 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.multi-tier,borland.public.delphi.database.multi-tier
Subject: Re: My IAppServer function barfs using ScktSrvr
References: <3c0b70e0_1@dnews>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 163.12.6.214
X-Trace: dnews 1008429630 163.12.6.214 (15 Dec 2001 07:20:30 -0800)
Lines: 102
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-out.visi.com!hermes.visi.com!out.nntp.be!propagator-SanJose!in.nntp.be!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews