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
 Error: Calling members of unattached wrapper class
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Belsinga

Netherlands
28 Posts

Posted - 05/31/2010 :  02:50:19 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8 SR 6
Operating System: Win XP

Hello,

I am working on a script that enables the user to select graphs from the worksheet and merge two. Afterwards the originals should be destroyed. The script works fine, but returns an error before completing. The error is: "Calling members of unattached wrapper class"

The error occurs in the "foreach" loop. How can I tell Origin to kill the selected graphs (those that are in the vectorstring that was created in the selection dialog screen) from within the foreach-loop?

=========================================
foreach(gp in Project.GraphPages)
{
int TEST = vsGraphs.GetSize();
if(TEST>0)
{
for(int n = TEST-1 ;n>=0; n--)
{
if(gp.GetName() == vsGraphs[n])
{
printf("*");gp.Destroy();
}
}
}

}

Belsinga

Netherlands
28 Posts

Posted - 05/31/2010 :  02:52:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
PS

the error is located at the line of the "if(gp.GetName() == vsGraph[n])" statement.
Go to Top of Page

Penn

China
644 Posts

Posted - 05/31/2010 :  04:29:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Maybe you can try to use the GetName method derived from PageBase class like below.

foreach(gp in Project.GraphPages)
{
	int TEST = vsGraphs.GetSize();
	if(TEST>0)
	{
		for(int n = TEST-1 ;n>=0; n--)
		{
			string strName;
			bool bRet = gp.GetName(strName);
			if(bRet && (strName == vsGraphs[n]))
			{
				printf("*");
				gp.Destroy();
			}
		}
	}
}

This prototype derived from OriginObject class can also be used, but need to assign to a string variable.

foreach(gp in Project.GraphPages)
{
	int TEST = vsGraphs.GetSize();
	if(TEST>0)
	{
		for(int n = TEST-1 ;n>=0; n--)
		{
			string strName = gp.GetName();
			if(strName == vsGraphs[n])
			{
				printf("*");
				gp.Destroy();
			}
		}
	}
}


Penn
Go to Top of Page

Belsinga

Netherlands
28 Posts

Posted - 05/31/2010 :  05:26:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the quick reply. It didn't quite work, but I managed to replace the for loop by manually selecting n=0 and n=1 and now the problem is solved.

Regards,
Boudewijn.
Go to Top of Page

TreeNode

64 Posts

Posted - 05/31/2010 :  05:34:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Belsinga,

I think its not a surprise that you get the error:
"Calling members of unattached wrapper class"

Your foreach loop operates on every GraphPage which exist in your project.
Lets imagine you have 3 GraphPages in your project. You stored the Names of these
in your vector: vsGraphs

Now your code starts:
foreach(gp in Project.GraphPages)
{
	int TEST = vsGraphs.GetSize();
	if(TEST > 0)


In the first round of the loop gp is attached to the first Graph.
TEST holds the number of GraphNames in your vector.

your code goes on:
for(int n = TEST-1; n >= 0; n--)
		{
			if(gp.GetName() == vsGraphs[n])
			{
				printf("*");
				gp.Destroy();
			}

		} // for int n


Here you destroy all GraphPages which are named by the strings holded in your vector.
Now the foreach loop is at the end and starts from beginning.
Your GraphPage object gp should now be attached to the second GraphPage in your Project.
But you destroyed it a few lines ago...

...thats why you get exactly the error mentioned above. You try to attach to a GraphPage,
taht doesnt exist any more. The GraphPage object gp stays UNATTACHED for that reason.
And now you want to call a member function gp.GetName(). At that point you get the error.

So why do you want to destroy the GraphPages from inside the foreach loop?
Destroy them from outside the foreach loop and I think everything is fine.



|-- TreeNode
...|-- a??
...|-- ha!!
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