Saving a balloon

I am in the process of building a “save to database” function in my test program. I save goSimpleNodes fine, but I assumed that on the goBalloon the anchor property would tell me what to relink it to later when I rebuild the view. However, anchor only seems to tell me I am anchored to a goSimpleNode. This is the code I am using in the for each loop:
GoBalloon bN = obj as GoBalloon;
if (bN != null)
{
string nType = “goBalloon”;
string nPartID = bN.PartID.ToString();
string nText = bN.Text.ToString();
string nXleft = bN.Left.ToString();
string nYtop = bN.Top.ToString();
if (bN.Anchor != null)
{
nAnchor = bN.Anchor.ToString();
}
after I issue the insert command into my database, the field value says: Northwoods.GoWeb.GoSimpleNode.
Help. Thanks

You’ll need to save some unique identifier for that Anchor object (which I guess is a GoSimpleNode in your case).
Then upon loading you will need to find that object to be the Anchor. But note that, depending on how you organize your save code, at the time you load your balloon object the anchor object might not exist yet in your GoDocument. So you might need to have a separate pass at the end of the load to resolve these references.

I’m sorry, but I am confused. The object that the balloon is attached to is a simple node and when it gets saved, I save off the partid. So, I think I am doing what you suggest in your first sentance. But I still don’t see how the I can find the object on load unless I know the partid of the anchor as I am saving the balloon. Something like nAnchor = bN.Anchor.PartID.ToString(); except that as far as I can see there is no anchor.partid.
Sorry for being lost on this.

The GoBalloon.Anchor property can be any GoObject in the same document. It doesn’t have to be an IGoIdentifiablePart (as GoSimpleNode is), so it doesn’t have to have a PartID.
When storing your document:
IGoIdentifiablePart part = bN.Anchor as IGoIdentifiablePart;
if (part != null) {
… save part.PartID …
}
When loading your document:
GoBalloon balloon = … create and initialize from saved info …
int anchorpid = … get saved PartID of Anchor …
if (anchorpid != -1) {
IGoIdentifiablePart anchor = document.FindPart(anchorpid);
if (anchor != null) {
balloon.Anchor = (GoObject)anchor;
} else {
… remember both BALLOON and ANCHORPID so that you can try
… calling GoDocument.FindPart in another pass to resolve
… references from GoBalloons to not-yet-created GoSimpleNodes
}
}
If you make sure you write out all the GoSimpleNodes before you write out any GoBalloons, you won’t need to worry about any unresolved references, so you won’t need to implement this additional pass.

Ok, I’m back to rebuilding the balloons. (btw, nodes and links are all loading great now).
Based on the code you gave me above, I wrote the following:
case “goBalloon”:
GoBalloon b = new GoBalloon();
b.Text = dr[“nText”].ToString();
b.Reanchorable = true;
b.PartID = (int)dr[“nPartID”];
b.Text = dr[“nText”].ToString();
pid = Convert.ToInt32(dr[“nAnchor”].ToString());
if (pid != -1) {
IGoIdentifiablePart anchor = MyView.Document.FindPart(pid);
if (anchor != null) b.Anchor = anchor;
}
b.Left = (float)x;
b.Top = (float)y;
MyView.Document.Add(b);
break;
When I build the solution, there is an error referring to the underlined line above: Error 2 Cannot implicitly convert type ‘Northwoods.GoWeb.IGoIdentifiablePart’ to ‘Northwoods.GoWeb.GoObject’. An explicit conversion exists (are you missing a cast?)
Appreciate the help. Probably something simple as usual.
Mark

Hi Walter. Any ideas on my post above?

The compiler error message says what the problem is. I have fixed my code above, which obviously I had typed in without trying to compile it.