Delphi’s handling of variant arrays
is somewhat closer to that of C or C++ than Visual Basic. It provides
three functions to find the number of dimensions in a variant array
and the high and low bounds of a given dimension. The first of these,
VarArrayDimCount, is extremely useful and
something VB lacks; the easiest way to find this from VB is to ask
for the bounds of higher and higher dimensions until an error occurs.
dimension) are the equivalents of
returned from Python always have a lower bound of zero.
If you want to iterate over a 1D array, you can’t use a
each loop as in VB; instead
you need to find the upper bound of the array. Here’s the code
to update a list box of accounts:
procedure TfrmMain.UpdateAccountList; var AccountList: Variant; i: integer; begin lstAllAccounts.Items.Clear; AccountList := BookServer.GetAccountList; for i := 0 to VarArrayHighBound(AccountList, 1) do lstAllAccounts.Items.Add(AccountList[i]); end;
The array has one dimension, so ask for the upper bound of dimension 1.
AccountList[i] returns a
Variant, which Delphi coerces to a string when
adding to the list box.
Delphi also offers more functions for constructing
Variant arrays of given dimensions, which can
efficiently pass data to Python.
Unfortunately this isn’t so easy as with Visual Basic. In VB, every user interface object and class ...