I have a conceptual problem, and I can't figure out the most effective way to do it. I have two objects of the exact same type, but I want one to be the "parent" of the other, so that when I manipulate one object I can then call back and perform functions on the parent as well.
In short, when I create the "child", I want the "parent" to become inactive (through a flag setting). When the child has finished doing what it is going to do, I want it to reactivate (through the same flag) the parent.
I thought of creating parent/child lists, but iterating through lists to find a single object seemed inefficient. I also considered using pointers, but I'm not comfortable enough with how Blitz handles memory to be sure of the form. This is the kind of thing I wanted to do:
Any suggestions are welcome. I'd really rather avoid pointers altogether, but I can't think of any other way that doesn't involve looking through a "ParentList" or ChildList" etc...
In short, when I create the "child", I want the "parent" to become inactive (through a flag setting). When the child has finished doing what it is going to do, I want it to reactivate (through the same flag) the parent.
I thought of creating parent/child lists, but iterating through lists to find a single object seemed inefficient. I also considered using pointers, but I'm not comfortable enough with how Blitz handles memory to be sure of the form. This is the kind of thing I wanted to do:
'----------------------------------------------------------- '***********************Widget Type ************************ '----------------------------------------------------------- Type Widget Field Name$ = Null Field Uses =0 Field pos_x,pos_y Field Is_child = False Field Parent:Widget Ptr = Null Field Is_Active = True Global WidgetList:TList '*************************Create**************************** Function CreateWidget:Widget(temp_name$,x,y,num_uses) temp_widget:widget = New widget temp_widget.name = temp_name temp_widget.pos_x = x temp_widget.pos_y = y temp_widget.uses = num_uses If WidgetList=Null Then WidgetList = CreateList() WidgetList.AddLast(temp_widget) Return temp.widget End Function '***********************Make Widget a child of another ************** Method MakeChild (in:widget Ptr) Is_child = True parent = in End Method '********************** Where the Widget does stuff, and where it turns off the parent!!!!! Method DoStuff() Var Parent.MakeInactive() 'This is where I try to make the parent object inactive but ' it doesn't work. I need to know either how to make the ' pointer able to refernce the method of the object or a ' better way to do this! ...... Do other stuff .... 'All the rest of the programming. Var Parent.MakeActive() ' Same issue... End Method ' ********************* Sets Flag to active ************************ Method MakeActive () Is_active = True End Method '***********************Sets flag to inactive ******************** Method MakeInactive() Is_active = False End Method End Type '---------------------------------------------------------------- '******************** Starts the main program ******************* '---------------------------------------------------------------- Global thing1:widget = Widget.CreateWidget ("First",1,1,0) Global thing2:widget = Widget.CreateWidget ("Second",1,1,0) thing2.MakeChild(Varptr thing1) thing2.DoStuff() '<----------------- The parent should be inactive While this is happening
Any suggestions are welcome. I'd really rather avoid pointers altogether, but I can't think of any other way that doesn't involve looking through a "ParentList" or ChildList" etc...