Board index » delphi » Varinat array to open array

Varinat array to open array

I am creating an OLE interface to some of our objects in Delphi 2. One
method checks if a set of column names and values exists. The object method
is:

function TOurObject.KeyExists(const ColNames: array of String; const
ColValues: array of Variant): Boolean;

The OLE automated method is:

function TOleObject.KeyExists(const ColNames, ColValues: Variant):
WordBool;

I need to convert the ColNames and ColValues variant arrays to open arrays
to be passed to then object method. I cannot change the object KeyExists
method parameter declaration. Does anyone know how to create open array
parameters at run-time?

Thanks in advance.

Tim

______________________________

Tim Parker-Nance

Orion Software
PO Box 27126, Greenacres
Port Elizabeth, 6057
South Africa

  Tel: ++27 (0)41 311506
  Fax: ++27 (0)41 351961
 Cell: ++27 (0)82 6592897
Email: rpear...@aztec.co.za

 

Re:Varinat array to open array


Quote
rory pearton wrote:

> I am creating an OLE interface to some of our objects in Delphi 2. One
> method checks if a set of column names and values exists. The object method
> is:

> function TOurObject.KeyExists(const ColNames: array of String; const
> ColValues: array of Variant): Boolean;

> The OLE automated method is:

> function TOleObject.KeyExists(const ColNames, ColValues: Variant):
> WordBool;

> I need to convert the ColNames and ColValues variant arrays to open arrays
> to be passed to then object method. I cannot change the object KeyExists
> method parameter declaration. Does anyone know how to create open array
> parameters at run-time?

> Thanks in advance.

> Tim

> ______________________________

> Tim Parker-Nance

> Orion Software
> PO Box 27126, Greenacres
> Port Elizabeth, 6057
> South Africa

>   Tel: ++27 (0)41 311506
>   Fax: ++27 (0)41 351961
>  Cell: ++27 (0)82 6592897
> Email: rpear...@aztec.co.za

This is just a guess as I haven't tried it, but

1. Use the VarArrayDimCount, VarArrayLowBound, and VarArrayHighBound
functions to determine the number of elements you need in the open
arrays.

2. Allocate the memory for the arrays yourself using code something
like:

type StringArray = array[0..999] of string; // or some other big number
type PStringArray = ^StringArray;
...
var
  psa: PStringArray;
...
  GetMem(psa, sizeof(string) * NumOfElements);

3. Initialize the array with the data from the variant arry (for array
of string you probably have to first set every element to binary zeros;
I'm not sure what, if anything, you have to do for variants).

4. Call TOurObject.KeyExists using the Slice function for the parameters
e.g. Slice(psa^, NumOfElements).

5. Remember to free the memory with FreeMem(psa). For array of string
you should probably first free all the strings by assigning '' to each
element. I'm not sure if you need something similar for the variants.

Hope this helps
Chris Jobson

Other Threads