Re: Problem with packaged params in DataRequest call


2005-02-27 10:41:28 PM
off-topic4
Staffan wrote:
Quote
I am trying in a datasnap application (in Delphi 6) to send a procedure call
with parameters via the ClientDataSet.DataRequest - as in the test example
below.
I want to replace some COM-calls using only datasnap instead.

On the method call I get "Bad variable type".

Can't figure out how to transform the OleVariant - that seems to be an array
of variants - so that this will work.

Anyone who has an example of how to do it?
Or is the idea totally wrong?

Thanks in advance!

Staffan


Example:procedure TForm2.Button4Click(Sender: TObject);
var CallParams : TParams;
SendVariant, ReceiveVariant : OleVariant;

begin
CallParams := TParams.Create(nil) ;

with CallParams do
begin
// Create params
CreateParam(ftinteger, 'Intpar1', ptinput);
CreateParam(ftstring, 'Stringpar1', ptinput);

// add data
ParamByName('Intpar1').AsInteger := 1;
ParamByName('Stringpar1').AsString := 'hello';
end;

// pack params
SendVariant := PackageParams(CallParams, AllParamTypes);

try
// error comes here
ReceiveVariant := CDSemployee.DataRequest(SendVariant);

Except
on E: Exception do
begin
EditError.Text := E.Message;
end;
end;

CallParams.Free;
end;




DataRequest sends and returns an OleVariant but it can't handle variant
array of variants (at least if Dimensions>1) well. The best approach is
to convert the OleVariant to a variant array of VarBytes. You can do
this in two steps: (or in any other way you like)
1) Use CodeCentral 19613 Var2Str function to convert Variant to a
long string
2) Use StringToVariantArray (DsIntf.pas) to get the result Variant
3) Follow the reverse approach when "decoding" you OleVariant
The code generated this way is not very efficient (you can always refine
it) but requires only a few lines of code from your perspective