Jump to content

GObject To More Specific Class from Class ID


jcarmody

Recommended Posts

I'm trying to help in this thread and came to a roadblock. I want to be able to examine the Label.Text of any GObject that has a Label.Text property without using a Case Structure to handle every type as I did in my solution there. My thought was that I could use the Class ID property of the GObject to cast the reference to the specific type of object and check if it has a Label.Text property. This brings up a few questions:

  1. Is it possible to get a type-specific Constant Refnum from the Class ID? How?
  2. Once I have the Constant Refnum, how can I get keep the property node from breaking (see below)?

post-7534-0-00041200-1292940055_thumb.pn

Link to comment

  1. Is it possible to get a type-specific Constant Refnum from the Class ID? How?
  2. Once I have the Constant Refnum, how can I get keep the property node from breaking (see below)?

1. Hmm, I get from ClassName 'BooleanConstant' and the like. But your code in the other thread already does this, so propably I misunderstand your question.

2. Not possible. Constant has the Lable property, it's parent GObject has not. Other childs of GObject have it as well, but you need to downcast them explecite as well.

Felix

Link to comment

If they all have the Label.Text property, you can type cast the reference to a class which has it (e.g. the Control class) and use it with that. Note that type casting references can be dangerous, so if you want to be safe, I would go with trying TMSC down to each relevant class until you don't get an error or get the class ID to know which specific class it is.

If you do use the type cast method, I suggest you only use it for the Label.Text property and then go back to working with the original reference.

Link to comment

I'm trying to help in this thread and came to a roadblock. I want to be able to examine the Label.Text of any GObject that has a Label.Text property without using a Case Structure to handle every type as I did in my solution there. My thought was that I could use the Class ID property of the GObject to cast the reference to the specific type of object and check if it has a Label.Text property. This brings up a few questions:

  1. Is it possible to get a type-specific Constant Refnum from the Class ID? How?
  2. Once I have the Constant Refnum, how can I get keep the property node from breaking (see below)?

You can relink the Label.Text property by setting the StringID of the "Property Item". However, it seems that there is a bug with writing the Property Item String ID for Text Label... I can change easily the property of the node by giving the correct String ID for any top-level property such as Indicator or KeyFocus, but when I input the string ID of any property that is a child of another property (ex: Label >> Text), then it returns an error. Perhaps I don't do it right, but I presume it has to do with the fact that the "All Supported Properties" doesn't return the children...

So a workaround would be to set the Property Node for "Label" (string ID: 6332005) and then add a property node for Text...

post-10515-0-97874500-1292945581_thumb.p

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.