The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 SafeArray
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jguenrdc

USA
Posts

Posted - 05/23/2006 :  12:41:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version: OriginPro 7.5 SR6 v7.5885(B885)
Operating System: Windows XP Pro SP2

I would like to call an ADO method that takes 2 SafeArrays as parameters. Where can I find information about working with SafeArrays in Origin C? The ADO function in question is:

AddNew Method
Creates a new record for an updatable Recordset object.

Syntax
recordset.AddNew FieldList, Values
Parameters
recordset
A Recordset object.
FieldList
Optional. A single name, or an array of names or ordinal positions of the fields in the new record.
Values
Optional. A single value, or an array of values for the fields in the new record. If Fieldlist is an array, Values must also be an array with the same number of members; otherwise, an error occurs. The order of field names must match the order of field values in each array.

I have successfully used it with a single value for each paramter:
ocrs.AddNew(1,ScoutHead.FDeployID);

I would like to use the array version so I can set several fields before the record is added to satisfy the restraints defined for my database.

Jay

ML

USA
63 Posts

Posted - 05/23/2006 :  3:53:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi jguenrdc,

Here is a simple example which shows how to create a safearray of variants and put some strings into it:


#include <variant.h>
#include <VariantTypes.h>


void test_safearray()
{
StringArray vstrValues = {"First string", "Second string", "Third string", "Fourth string"};
int nSize = vstrValues.GetSize();

// The safearray:
_VARIANT varSafeArray;
if ( !varSafeArray.CreateAsArray(VT_VARIANT, nSize) )
{
out_str("Failed to create safe array!");
return;
}

for (int ii = 0; ii < nSize; ii++)
{
_VARIANT var;
string str = vstrValues[ii];
var = str;

varSafeArray.SetOneVariantInArray(var, ii);
}

return;
}


Go to Top of Page

jguenrdc

USA
Posts

Posted - 05/24/2006 :  12:03:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ML,

Thank you for the code sample, that was enough to help me figure it out.

Jay
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000