How to pass arrays to ActiveX controls?

I am trying to use a function of an ActiveX control that takes an array as
parameter (via an OleVariant) as follows:

procedure PutItems(var Items: OleVariant; var Index: OleVariant);

The documentation for the control says that Items must be either a 1-
dimensional array of string or variants, or a 2-dimensional array of strings
or variants.  I construct a variant array in Delphi using VarArrayCreate with
a VarType of either varOleStr or varVariant and then insert my data as
strings, but when I call PutItems, I get an Access Violation.

Here's a sample of some of my test code:

procedure TForm1.Button1Click(Sender: TObject);
var
   Items1, Index: OleVariant;
   Row: Integer;
begin
   Index := 0;
   // AddItem works
   Control1.AddItem('test', Index);

   // 1-dimensional array PutItems gives access violation
   Items1 := VarArrayCreate([0,4], varOleStr);
   for Row := 0 to 4 do
     Items1[Row] := 'Test' + IntToStr(Row);
   // Access violation occurs on this call:
   Control1.PutItems(Items1, Index);
end;

Is there another way I should be creating my strings or assigning them to the
Variant Array so that they will be safe across the ActiveX call?  Any and all
suggestions are appreciated.

Thanks,
-rich
rjo...@uplinkgolf.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own