object help please
BlitzMax Forums/BlitzMax Beginners Area/object help please
| ||
im creating a little gui system I have gadget types like: type gui_element field gadget_number endtype type button extends gui_element endtype type textbox extends gui_element endtype I want to gather the gadgets onto a window so in my window class I have a list of gadgets that it contains type window field gadget_list:tlist method add_gadget_to_window(o:object) o.gadget_number=gadget_list.count()+1 endtype endtype but I cant access the field gadget_number from o:object how do I do that? |
| ||
Change method add_gadget_to_window(o:object) To method add_gadget_to_window(e:gui_element) |
| ||
it compiles now thanks but throws an error:'trying to access field or method of null object' here is the actual method: Method add_gadget(o:gui_element) gadget_list.addlast(o) -this is the line that throws the error - o.gadget_number=gadget_list.count() EndMethod im absolutely sure that gui_element has a field called gadget_number dont know why it does this |
| ||
Are you sure gadget_list isn't null? |
| ||
pretty sure: I changed the line o.gadget_number=gadget_list.count() to o.gadget_number=1 and it still threw the error. shall I show ALL the code? its 300 lines with spaces I had a look at frygui,highgui and c64's GUI code none of them do it like I am attempting all of those other GUI systems have a list of children on the gui_element base type. So maybe what I am attempting is impossible? |
| ||
In that case, you're sending an object to that function which either does not exist or is not derived from gui_element. But yeah, if you don't mind posting all the code, I don't mind taking a look. Those GUI systems you mention might not work by deriving all their gui_elements from a base type, but mine does, so unless there's more to this than meets the eye, I'm sure it's possible. |
| ||
thanks for taking a look I can change the loadimage commands if you want to run the program for yourself instead of creating a window, I tried to create a gadget scroller that had a list of gadgets - like a list of buttons and textboxes |
| ||
Your Create function within the Button type is not returning the object it creates, so you're passing a null object when you call g.addgadget(b) Change the create function in Button to this: Function Create:button(x , y , width:Float , height:Float , text$) Local t:button=New button t.x = x t.y = y t.width = width t.height = height t.text = text If img = Null img=gui_type.gui_pointer.button_img img2=gui_type.gui_pointer.button_over_img Return t EndIf And you should be fine. |
| ||
oops, it works now thanks! |