Tangled in OOP knots!

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

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

Type TScreen
	Field sName:String
	Field background:TImage 

	
	' Create a list of buttons belonging to the screen
	Field buttons:Tlist	=	New Tlist			
	
	'Creates a list of screens
	Global ScreenList: TList	
	
	Function UICreateScreen:TScreen(name:String, image:String, totalButtons:Int)
		Local NewScreen:	TScreen
		NewScreen	=	New TScreen
		NewScreen.sName	=	name$
		NewScreen.background	=	LoadImage(image$)

		' Verfiy files exist and are of correct size
		Assert NewScreen.background Else "Cannot find file '"+image$+ "'."
		Assert NewScreen.background.width=iScreenWidth Else "Background: "+image$+" size does Not match screen width."
		Assert NewScreen.background.height=iScreenHeight Else "Background: "+image$+" size does Not match screen height."
		If Not screenlist Then ScreenList:Tlist = CreateList()
	
		' Once all checks are done add screen to list
		ScreenList.addlast ( NewScreen)
		
		
		'Create a list of buttons which will be a part of this screen
		For Local temp=1 To totalButtons
			NewScreen.buttons.addlast( New TButton)
		Next
		
		'This should return the object just created so we can access it at a later date
		Return NewScreen
	EndFunction
	
EndType

Type TButton
	Field sName:String
	Field x:Int
	Field y:Int
	Field normal:TImage			Field link:Int
	Field iCellWidth:Int=169  
	Field iCellHeight:Int=75
	Field iTotalFrames:Int=0
endtype


Global MainMenu: TScreen
MainMenu=TScreen.UICreateScreen("MainMenu","background.png",5)


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()
...


Great thanks - but in AddButton you have to add the button to the list once its created yeah?

yes, sorry I'Ve forgotten that small part ;)

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.

oops

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