🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

What's wrong with my codes?

#995
From: George Wei
Date: Fri, 11 Aug 2000 00:00
80 lines
3017 bytes
I have implemented an application server in both C++ Builder 5 & Delphi 5. 
The only difference between them is the codes of an interface's 
implementation.
The following are the same steps in CB5 & D5:
1. New an ActiveX Library;
2. New a Remote Data Module (name it as MIDASServer);
3. Put an ADOConnection(ADOConnection1), 2 ADOQuerys(ADOQuery1, ADOQuery2), 
a DataSetProvider(DataSetProvider1) in MIDASServer;
4. Open Type Library editor, new a funtion named VerifyPassword of 
interface IMIDASServer as the following:

    HRESULT _stdcall VerifyPassword([in] BSTR Username, [in] BSTR Password, 
[out, retval] VARIANT * RetVal );

5. The following implementation of function VerifyPassword is different in 
CB5 & D5:

//---In CB5---
STDMETHODIMP TMIDASServerImpl::VerifyPassword(BSTR Username, BSTR Password,
  TVariant* RetVal)
{
  AnsiString S;

  if(m_DataModule->ADOQuery2->Active==true)
    m_DataModule->ADOQuery2->Close();
  m_DataModule->ADOQuery2->Parameters->ParamByName("Username")-
>Value=UpperCase(Username);
  m_DataModule->ADOQuery2->Open();
  S=m_DataModule->ADOQuery2->FieldByName("Password")->AsString;
  m_DataModule->ADOQuery2->Close();
  if(S==AnsiString(Password))
    return S_OK;
  else
    return E_FAIL;
}

//---In D5---
function TMIDASServer.VerifyPassword(const Username,
  Password: WideString): OleVariant;
var
  S : AnsiString;
begin
  if(ADOQuery2.Active=true) then
    ADOQuery2.Close;
  ADOQuery2.Parameters[0].Value:=UpperCase(Username);
  ADOQuery2.Open;
  S:=ADOQuery2.Fields[0].AsString;
  ADOQuery2.Close;
  if(S=AnsiString(Password)) then
    result:=S_OK
  else
    result:=E_FAIL;
end;

At last, I implement a procedure in a client program in D5 to call these 2 
server's function VerifyPassword as the following:

procedure TFormSecurity.btnOKClick(Sender: TObject);
var
  hr:HRESULT;
begin
  if(DCOMConnection1.Connected=false) then
    DCOMConnection1.Connected:=true;
  hr:=DCOMConnection1.AppServer.VerifyPassword(edtUsername.Text,edtPassword
.Text);
  if(SUCCEEDED(hr)) then
    ShowMessage('Succeeded.')
  else
    ShowMessage('Failed.');
end;

The problem is, when the both servers return S_OK, the client can show the 
message 'Succeeded.' correctly; when the servers tries to return E_FAIL, 
the client shows the message 'Failed.' correctly when calling the D5 
version, but it gets the following exception info:

Project Client.exe raised exception class EOleException with
message 'Cannot specified error'. ...

What's wrong with my codes of the CB5 version? Thanks to any help.
Technical Details
Message-ID: <8n0eql$fm65@bornews.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcd2b,630192ac7ec8b758,start
X-Google-Attributes: gidfcd2b,public
From: gweii@21cn.com (George Wei)
Subject: What's wrong with my codes?
Date: 2000/08/11
Message-ID: <8n0eql$fm65@bornews.borland.com>
X-Deja-AN: 657090484
Organization: SolarWinds
User-Agent: Xnews/03.01.23
Newsgroups: borland.public.cppbuilder.database.multi-tier