Tangled in OOP knots!

BlitzMax Forums/BlitzMax Beginners Area/Tangled in OOP knots!

Ant(Posted 2005) [#1]
Hi all, having a braint twist with an OOP concept. Below I have declated a type TScreen and a method to create a screen. Within this type, I've also declared a list of buttons which I want to associate with this screen.
I think this is all pretty standard. However, I'm unsure once I've created this list of buttons of how to access them once they have been created. How would I go about assigning fields to the first button and how would I know if a button already exists?
Thanks




klepto2(Posted 2005) [#2]
Maybe something like this (pseudo code):
Type TScreen
	Field Button_List:TList
	
	Function create:TScreen() ' Without Buttons
	
	End Function
	
	Method AddButton:TButton()
		If Not Button_List Then Button_List = New TList
		Local Button:TButton = New Tbutton
		Return Button
	End Method
	
End Type

Type TButton
	Field xyz
End Type

Screen:TScreen = TScreen.Create()
Button1:TButton = Screen.AddButton()
...



Ant(Posted 2005) [#3]
Great thanks - but in AddButton you have to add the button to the list once its created yeah?


klepto2(Posted 2005) [#4]
yes, sorry I'Ve forgotten that small part ;)


Ant(Posted 2005) [#5]
Hmm, ok I've done that but then the buttons arent part of TScreen. Bascially I want to have code in which I can create and assign buttons to a screen and a loop will automatically draw any buttons assoiciated with that screen...the list for that screen is present, but I essentially need to assign properties to the buttons in an already created list. Any ideas?
Thanks.


Eric(Posted 2005) [#6]
oops


Eric(Posted 2005) [#7]
How about

Add a Field to TScreen
Field Buttons:Tlist


Then when you create a new screen

Buttons=Createlist()


Under Tbutton you Create a
Field Parent:Tscreen


Under TButton

Function
   Create:Tbutton(Screen:TScreen)
   Local Button:Tbutton=new TButton
   Button:Parent=Screen
   ListAddLast Screen.Buttons,Button
End Function


This way each button knows it's parent Screen.

Just an Idea. I hope this makes sense. and that I uderstood what you were after.

Eric