Share this page

# Example: lrc_variant_<Type-Name>Array_by_ref

This example demonstrates that the lrc_*_ByRef class of functions deals with references to the underlying data, and not the data itself.

    VARIANT vRef, vRef1;
    FloatArray array0, array1, array2;
    float fValue;

    // Create and populate an array
    array0 = Create1DFloatArray(0, 5);
    PutElementIn1DFloatArray(array0, 0, lrc_float("1.1"));
    PutElementIn1DFloatArray(array0, 1, lrc_float("20.02"));
    PutElementIn1DFloatArray(array0, 2, lrc_float("300.003"));
    PutElementIn1DFloatArray(array0, 3, lrc_float("4000"));
    PutElementIn1DFloatArray(array0, 4, lrc_float("50000"));

    // Get an element from the array and display it
    fValue = GetElementFrom1DFloatArray(array0,1);
    lr_output_message("Second element in array0 = %f", fValue);

    Example: Output:
    Action.c(20): Second element in array0 = 20.020000

    // Get references to the array with two possible syntaxes
    vRef = lrc_variant_FloatArray_by_ref(array0);
    vRef1 = lrc_PutFloatArrayByRefInVariant(array0);

    //Convert the reference to a float array
    array1= lrc_GetFloatArrayFromVariant(&vRef);

    // Get an element from the new array and display it
    fValue = GetElementFrom1DFloatArray(array1,1);
    lr_output_message("Second element in array1 = %f", fValue);

    Example: Output:
    Action.c(30): Second element in array1 = 20.020000

    //Change an element in the original array
    PutElementIn1DFloatArray(array0, 1, lrc_float("101.99"));

    // Get an element from the original array and display it
    fValue = GetElementFrom1DFloatArray(array0,1);
    lr_output_message("Second element in array0 after change = %f", fValue);

    Example: Output:
    Action.c(38): Second element in array0 after change = 101.989998

    // Get an element from the new array and display it. It's the same array
    fValue = GetElementFrom1DFloatArray(array1,1);
    lr_output_message("Second element in array1 after change to array0 = %f", fValue);

    Example: Output:
    Action.c(43): Second element in array1 after change to array0 = 101.989998

    /* Confirm that what we've been passing is references to the same array
    by showing that the addresses are the same.*/
    if (array0 == array1) lr_output_message("There is only one array");

    Example: Output:
    Action.c(46): There is only one array

    // Used different syntax above to get the reference, but still the same array.
    array2= lrc_GetFloatArrayFromVariant(&vRef1);
    fValue = GetElementFrom1DFloatArray(array2,1);
    lr_output_message("Second element in array2 after change to array0 = %f", fValue);

    Example: Output: Action.c(53): Second element in array2 after change to array0 = 101.989998

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: