2.2.3.6.2 Dataset::Attach

Description

Attach Dataset object to an Origin data set identified by name.

Attach a Dataset object to a worksheet column identified by worksheet name and column number.

Attach a Dataset object to a worksheet column identified by Worksheet object and column number.

Attach a Dataset object to a worksheet column identified by a Column object.

Syntax

BOOL Attach( LPCSTR lpcszDatasetName )


BOOL Attach( LPCSTR lpcszWksName, int nCol )


BOOL Attach( Worksheet & wks, int nCol )


BOOL Attach( Column & col )

Parameters

lpcszDatasetName
[input] Name of Origin data set to attach to


lpcszWksName
[input] Name of worksheet in which column resides
nCol
[input] Origin C column number to attach to (nCol=1 attaches to second
column in worksheet)


wks
[input] Origin C worksheet object attached to an Origin worksheet
nCol
[input] Origin C column number to attach to (nCol=1 attaches to second
column in worksheet)


col
[input]Origin C column object attached to an Origin worksheet column

Return

Returns TRUE on successful exit and FALSE on error.


Returns TRUE on successful exit and FALSE on error.


Returns TRUE on successful exit and FALSE on error.


Returns TRUE on successful exit and FALSE on error.

Examples

EX1

void Dataset_Attach_ex1()
{
    Worksheet wks;
    wks.Create("origin", CREATE_VISIBLE);
    if(wks)
    {
        Dataset    ds1;               
        string strWksColAname = wks.Columns(0).GetName();
        strWksColAname = wks.GetPage().GetName() + "_" + strWksColAname;
        if(ds1.Attach(strWksColAname))  // Attach to the first column with column name
        {
            ds1.SetSize(10);
            for(int ii = 0; ii < 10; ii++)
                ds1[ii] = ii;
        }
        string strWksColBname = wks.Columns(1).GetName();
        strWksColBname = wks.GetPage().GetName() + "_" + strWksColBname;
        if(ds1.Attach(strWksColBname)) // Attach to the second column and detaches from previous column
        {                         
			ds1.SetSize(10);
			for(int ii = 0; ii < 10; ii++)
			ds1[ii] = -ii;
        }
    }
}


EX2

void Dataset_Attach_ex2()
{
    Worksheet wks;
    wks.Create("origin", CREATE_VISIBLE);
    if(wks)
    {
        Dataset    ds1;               
        string strWksname = wks.GetPage().GetName();
        if(ds1.Attach(strWksname,0)) // Attach to the first column with column index
        {
            ds1.SetSize(10);
            for(int ii = 0; ii < 10; ii++)
                ds1[ii] = ii;
        }
        if(ds1.Attach(strWksname,1)) // Attach to the second column and detaches from previous column
        {                         
            ds1.SetSize(10);
            for(int ii = 0; ii < 10; ii++)
                ds1[ii] = -ii;
        }
    }
}


EX3

void Dataset_Attach_ex3()
{
    Worksheet wks;
    wks.Create("origin", CREATE_VISIBLE);
    if(wks)
    {
        Dataset    ds1;          
        ds1.Attach(wks,1); // Attaching to different data set detaches from previous data set 
        ds1.SetSize(10);
        ds1 = 100;
    }
}


EX4

void Dataset_Attach_ex4()
{
    Worksheet wks;
    wks.Create("origin", CREATE_VISIBLE);
    if(wks)
    {
        string strWksname = wks.GetPage().GetName();
        Column colB(strWksname,1); 	// Declare an Origin C Column object attached to the second column
 
        Dataset    ds1;              
        ds1.Attach(colB); 			// Attach Dataset object to first column with column object
    }
}

Remark

Attach an Origin C Dataset object to an Origin worksheet column identified by an Origin C Column object. Origin C Dataset objects must be attached to internal Origin data sets either by constructor or by the Attach method.

See Also

Column::Column,Dataset::Dataset,Dataset::Detach,Worksheet::Worksheet

Header to Include

origin.h