AfterDBSetProp

COMArray()

This function controls how arrays are passed to COM objects. FoxPro's internal array handling is funky enough, but we have to support even more variations to successfully communicate with COM objects. This function lets us get there.

Usage

nCurrentType = COMArray( oObject [, nArrayType ] )

Parameter

Value

Meaning

oObject

Object

A reference to an object whose array-passing behavior you want to query or set.

nArrayType

Omitted

Returns the current setting for passing arrays for this object.

0

Pass a zero-based array by value.

1

Pass a one-based array by value. This is the default and the backward-compatible setting.

10

Pass a zero-based array by reference.

11

Pass a one-based array by reference.

100

Pass a fixed-size array that cannot be redimensioned. (Added in VFP 7.) This value can be added to the other values to fix the size of either a zero- or one-based array passed by either value or reference.

nCurrentType

Integer

The current (or new) setting.


In "Pass the Parameters, Please" in "Wow, What a Concept!" we talk about the trickiness involved in passing arrays from one FoxPro routine to another. The trick to remember is that UDFPARMS is set to Value (and that's a Good Thing), so to send an entire array to a function you need to precede the array name with an @ to pass it by reference.

It gets trickier when passing arrays out from FoxPro to a COM object. There are two separate gotchas involved, each addressed by this function. First, a COM object might expect things to be passed either by value or by reference. Second, the COM object might enumerate arrays by counting from 1 (the way we humans do it), or by starting at 0 (the way C++programmers do it), which is a little more efficient from the computer's view of things, though confusing as all get out to us. Starting in VFP 7, you have the option to prevent the array from being resized by adding 100 to the value for nArrayType.

You need to know which format the object is looking for, and set the settings here. There doesn't seem to be a way to sniff this out in advance. From what we've been able to tell with FoxPro acting as both client and recipient, Fox seems to be unaffected by this setting. But if your OLE server is from another source—say, VB, VC++ or Delphi—check with the vendor of the component for the right way to set this one.

Example

oDear = CreateObject("TestServer.cusServer") ? COMArray(oDear)       && Returns the default 1 ? COMArray(oDear,0)     && Displays 0 ? COMArray(oDear)       && Still displays 0 ? COMArray(oDear,10)    && Now it says 10 ? COMArray(oDear,11)    && And now 11 

See Also

CreateObject(), CreateObjectEx(), Set UDFParms


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net