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
 Copy Columns from one wks to another
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

origin_noob123

Germany
1 Posts

Posted - 12/02/2016 :  11:36:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
In a Origin C script I return in a function a vector with the DataObject of a column like this:

Vector function1 (){

Worksheet wks;
...
something happens with wks...
...

Column col(wks, 1);
Vector vec = col.GetDataObject();

return vec;
}

I now want to add the Column which I used in function1 to a new Worksheet in function2 like this

bool function2 (){

Worksheet wks2;
wks2.Create(NULL, CREATE_VISIBLE);
...
...
Dataset dsNew = *function1();
dsNew.Attach(wks2, 1);

return true
}

and then i get the error, that the dereferenciation is not valid. But i thougt vec is a Vector to a Dataset-Object? However it gets even more confusing: If I delete the * and only write Dataset dsNew = function1(); there is no error and compiling works, but it
gives me no values in wks2. Just an empty worksheet without any values. But wks1 is full at the same time!

What did i get wrong about the datatypes in Origin C?

Edited by - origin_noob123 on 12/02/2016 11:37:43 AM

yuki_wu

896 Posts

Posted - 12/05/2016 :  02:36:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think the following example can help you figure out the relationship in column, vector and dataset.

void DatasetAndVector_ex1()
{
    Worksheet wks = Project.ActiveLayer();// The current worksheet must have one column prior to execution
    if(!wks) 
    return;	
		
    Column col1 = wks.Columns(0);// 1st column
    int nRows = col1.GetNumRows(); // get the number of rows in the first column, also the size of the vector below
    vector &vec = col1.GetDataObject();// Get data object
	
	
    Dataset ds;            // Create Origin C Dataset object not attached to an Origin data set 
    ds.Attach(wks,1);  // Attach Origin C Dataset object ds to Origin data set wks(1)
    ds.SetSize(nRows); 
    ds = vec; // Assign values to dataset from vector.
}

Further, I think you’d better go through the document about column, vector and dataset:
http://www.originlab.com/doc/OriginC/ref/Column-Class
http://www.originlab.com/doc/OriginC/ref/vector
http://www.originlab.com/doc/OriginC/ref/Dataset

Regards,
Yuki
OriginLab
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