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.


|