Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pick > Success with De...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 3422 of 3595
Post > Topic >>

Success with Delphi 2007 & D3

by geneb@[EMAIL PROTECTED] (Gene) Mar 26, 2008 at 03:24 PM

The green-screen thread where Kevin and I had begun to discuss using Delphi
with D3 sparked my curiosity enough to take another look at the problem
and see if I could discover what was needed to correctly call the D3CLODBC
connectivity layer.

Well, I got it to work and below is the "test" routine that illustrates
how to do it.

The demo program consists of a form with a single Memo control and one
button.
I've used the default component names to make it easier to copy/paste
without
modification into your own demo program.

To use this example, you'll need to create a TLB unit for the D3CLODBC dll

using Component->Im****t Component and pick "Im****t a Type Library".
Chose the D3CLODBC.DLL file and the system will create a unit called 
"D3CLODBC_TLB".  

You will also need to use the ActiveX unit to obtain the SafeArray
routines.
(more commentary after the code)

procedure TForm1.Button1Click(Sender: TObject);
var
  aConn       : clsd3connection;
  anEnv       : clsd3Environment;
  aRec        : Tclsd3DynamicArray;
  aMod        : clsd3RuleModule;
  ParamArray  : PSafeArray;
  ParamBounds : Array[0..0] of TSafeArrayBound;
  ParamData   : OleVariant;
  inval,
  outval : WideString;
  ErrVal : longint;
  tempvariant : OleVariant;

  begin
    ErrVal := 0;
    Memo1.Lines.Add('Starting');
    anEnv := CoClsD3Environment.Create;
    aRec := TclsD3DynamicArray.Create(self);

    if anEnv <> nil then begin
      Memo1.Lines.Add('Init was ok.');
      aConn := anEnv.brOpenConnection('ODBC','Cheyenne');
      ErrVal := anEnv.brError(tempvariant);
      if ErrVal <> 0  then
        Memo1.Lines.Add('Error: ' + IntToStr(errval));

      if aRec <> nil then begin
        Memo1.Lines.Add('dynamic array created ok.');
        aRec.brReplaceStr('val1',1,1);
        aRec.brReplaceStr('val2',1,2);
        aRec.brReplaceStr('val3',1,3);
        Memo1.Lines.Add(arec.brExtractStr(1,1));
        Memo1.Lines.Add(arec.brExtractStr(1,2));
        Memo1.Lines.Add(arec.brExtractStr(1,3));
      end;

      ParamData := VarArrayCreate([0,1], varVariant); 
      ParamData[0] := 'Value In';
      ParamData[1] := '';  // value out
      ParamArray := PSafeArray(TVarData(ParamData).VArray);
      aMod := aConn.brOpenRuleModule('TEST.MODULE','VB.BP','WLPOINTERS');
      try
        aMod.brCall(ParamArray);
        Memo1.Lines.Add(ParamData[1]);
        aConn.brCloseRuleModule(aMod);
      Except
        on E : Exception do begin
             ShowMessage('Exception Class: ' + e.ClassName);
             ShowMessage('Exception message: ' + e.Message);
        end;
    end;
    aRec := nil;
    aMod := nil;
    anEnv.brCloseConnection(aConn);
    anEnv := nil;
  end;
end;

Here's the code for TEST.MODULE:

0001 subroutine test.module(inval, result)
0002 result = inval : " tada!"
0003 return

---

This is just a basic example.  I will build a more comprehensive example
if there is interest out there.

While the D3 class library may be kind of clunky, it appears to be the 
fastest and most direct to access data from D3 from a thick client
application.

Thanks to Kevin for making me poke my brain with a stick and figure this
silly
thing out. :)

g.
 




 5 Posts in Topic:
Success with Delphi 2007 & D3
geneb@[EMAIL PROTECTED]   2008-03-26 15:24:58 
Re: Success with Delphi 2007 & D3
Kevin Powick <kpowick@  2008-03-26 14:19:01 
Re: Success with Delphi 2007 & D3
geneb@[EMAIL PROTECTED]   2008-03-27 14:29:47 
Re: Success with Delphi 2007 & D3
Tony Gravagno <address  2008-03-29 17:58:28 
Re: Success with Delphi 2007 & D3
Kevin Powick <kpowick@  2008-03-27 12:08:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sat Jul 5 23:53:16 CDT 2008.