Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Arrays to ActiveX Objects 2

Status
Not open for further replies.

codenavigator

Programmer
Jun 14, 2002
14
US
I need to call an ActiveX object function from VFP 6.0. The function declaration is:

HRESULT PresetMultipleRegisters([in] short Addr, [in] long DataStart, [in] short Quantity, [in] VARIANT vRegValues)

In VB the syntax that works is:
Code:
<object>.PresetMultipleRegisters(1,4,3,array)

where array is declared as type Long.

In VFP I have tried passing the array as a value and as a reference:
Code:
(1)      <object>.PresetMultipleRegisters(1,4,3,array)
(2)      <object>.PresetMultipleRegisters(1,4,3,@array)

However, both statements produce an OLE error, &quot;Error building array&quot;.

What is the correct way to pass the array argument?
 
C/C++ and VB don’t recognize VFP array data type. This is simply because the array in VFP is more close to be structure than array.

In VB. VC++, the array is zero based – the first element is referenced by Array[0] – and the array elements has to be from the same data type meaning all of them are numeric or instance. In VFP, the array is one based – the first element is referenced by Array[1] – and you can mix types in the array.
So, to pass your array to a COM object you need to modify or specify the way it will be passed. COMARRAY() will do this for you. It is function in VFP to handle this situation.
Read the help for it, you will need to play a bit to detect the right setting combination since this function assumes that you already know what is your object will do for this array, will it redimension the array for example etc

Good luck

Walid Magd
Engwam@Hotmail.com
 
I am still experiencing trouble passing an array to the COM object after invoking COMARRAY(). I have tried various settings for the nNewValue argument (i.e., 0, 1, 10, and 11), but I always get the same error, &quot;Error building array&quot;.

The code looks like this:
Code:
o = CREATEOBJECT(&quot;modbussrv.modbussrv.1&quot;)
=COMARRAY(o,10)             && also tried settings of 1, 0, and 11
o.PresetMultipleRegisters(1,4,3,@array)   && array is a one dimensional array

Any suggestions?



 
Can you please tell me what is this Control is doing.
Do you need to instanciate it just for a function call and that is it?? or it will do another things for you during the application life time? Walid Magd
Engwam@Hotmail.com
 
The control sends and receives messages using Open Modbus protocol for controlling industrial processes via Ethernet TCP/IP. The class encapsulates twelve methods for establishing connections, reading registers, presetting registers, etc. The object is instantiated once and then function calls are made over the lifetime of the application.

VFP is being used as front end server in order to interface with other databases and applications written in VFP.
 
I have had the same problem using this function in DELPHI language today.
I solved my problem by declaring the array as an array of Type 'varInteger'.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top