Page 1 of 1

Name of object references

Posted: Fri Jul 25, 2008 5:57 am
by Raj
I have a GUI-element which uses an object passed as an argument during creation. I would like to be able to store the window in a session file, including the name of the objref passed when creating it.

My code is something like this:

Code: Select all

begintemplate myGUI
 objref myObject
proc init{
myObject =$o1
}

// More code among them the creation of a VBox or HBox called box

proc save(){
   box.save("load_file(\"myGUI.hoc\")\n}")
   // This is the kind of thing I would like to do (ocbox_ is an object created by the save (session) mechanism of the VBox or HBox )
    sprint(tstr, "{%s = new myGUI(%s)}", "ocbox_",name(myObject))   
    box.save(tstr)
}	
endtemplate myGUI


I had a look at the StringFunctions class. Which prints the desired information to screen with the references method, but gives no further access to them. There are some obvious workarounds, like passing both the objref and its name during creation, but that puts on us the burden of either deciding up front we are going to save the window or always specifying a string we might not use.

Does anybody have some ideas as to how to get to this information?

Re: Name of object references

Posted: Fri Jul 25, 2008 1:04 pm
by hines

Code: Select all

sprint(tstr, "%s", obj)
gives you the name of the object in
type[index] form. sscanf could be used to
parse it into base, index variables.
Or, see the classname() procedure in nrn/lib/hoc/stdlib.hoc as well
as object_index.

Re: Name of object references

Posted: Wed Jul 30, 2008 11:45 am
by Raj
Dear Michael,

That is not quite what I want. I think I would like to get my hands on the first name printed by the StringFunctions references method, which seems to be the name of the references in which the list was first stored in the global namespace.

Regards,
Ronald