It’s obvious that I don’t understand your code at all because I can’t even modify it to adapt it to what I want to do. Managing parent-child relationships seems very difficult for me, especially with recursive elements.
In my code, the type of an object was simply a string, not a real type. It was used to determine the type of an object in order to perform certain actions. For example, if Type = "Button", then do something.
If I have to integrate real object types into my code, it might become a jungle! But it could still be useful, I suppose.
Do you think I should integrate this into my Object Manager anyway?
Do you think it could be useful, especially for other people?
Because if you look at all the structure fields I’ve integrated into my object structure, and if every type of object has to have all these fields… interesting, but I don’t know.
It’s quite possible that once again, I’m failing to explain correctly what I want. That’s what happened with Editors Factory, where almost no one understood what it was for. I must admit, I have a lot of trouble explaining things.
To try, as best I can, to explain what I want: imagine you have lockers that represent objects, where I can store things and retrieve data. For example: “Hey, I want to store the value "24" in the locker called "Object 1", in the slot called "X". ”
Ah, ok. Maybe everyone already understood that. You don’t have to be a genius to get it. But what is it useful for? That’s another question. Well, so that I don’t have to redo everything, this management system could be useful if someone needs something ready-made for their project.
And since I need it myself, I want to create something that will be useful to others.
Code: Select all
Structure Object
*Parent.Object
ID.i
Type.s
Name.s
Texte.s
X.i
Y.i
Width.i
Height.i
Flags.i
EndStructure
Global NewMap MapObject.Object()
Procedure CreateObject(ParentID.i, ID.i, Type.s, Name.s, X.i, Y.i, Width.i, Height.i, Flags.i = 0)
Protected *Parent.Object
If FindMapElement(MapObject(), Str(ID))
ProcedureReturn 0
EndIf
If Not FindMapElement(MapObject(), Str(ParentID))
ProcedureReturn 0
EndIf
*Parent = MapObject()
AddMapElement(MapObject(), Str(ID))
MapObject()\Type = Type.s
MapObject()\ID = ID
MapObject()\Name = Name.s
MapObject()\Parent = *Parent
MapObject()\X = X
MapObject()\Y = Y
MapObject()\Width = Width
MapObject()\Height = Height
MapObject()\Flags = Flags
ProcedureReturn @MapObject()
EndProcedure
Procedure DeleteObject(ID)
If FindMapElement(MapObject(), Str(ID))
PushMapPosition(MapObject())
ForEach MapObject()
If MapObject()\Parent
If MapObject()\Parent\ID = ID
DeleteMapElement(MapObject())
EndIf
EndIf
Next
PopMapPosition(MapObject())
DeleteMapElement(MapObject())
EndIf
EndProcedure
Enumeration 1
#Object1
#Object2
#Child1_Object2
#Child1_Child1_Object2
#Child2_Object2
#Child1_Child2_Object2
#Child1_Child1_Child2_Object2
EndEnumeration
; Pas de parent.
*Object1.Object = CreateObject(0, #Object1, "Virtual", "Object 1", 0, 0, 200, 200)
; Pas de parent.
*Object2.Object = CreateObject(0, #Object2, "Virtual", "Object 2", 10, 10, 180, 25)
; #Object2 recoit un enfant: #Child1_Object2.
*Object3.Object = CreateObject(#Object2, #Child1_Object2, "Virtual", "Object 3", 10, 45, 180, 25)
; #Child1_Object2 recoit un enfant: #Child1_Child1_Object2.
*Object4.Object = CreateObject(#Child1_Object2, #Child1_Child1_Object2, "Virtual", "Object 4", 0, 0, 200, 200)
; #Object2 recoit un enfant: #Child2_Object2.
*Object5.Object = CreateObject(#Object2, #Child2_Object2, "Virtual", "Object 5", 10, 45, 180, 25)
; #Child2_Object2 recoit un enfant: #Child1_Child2_Object2.
*Object6.Object = CreateObject(#Child2_Object2, #Child1_Child2_Object2, "Virtual", "Object 6", 0, 0, 200, 200)
; #Child1_Child2_Object2 recoit un enfant: #Child1_Child1_Child2_Object2.
*Object7.Object = CreateObject(#Child1_Child2_Object2, #Child1_Child1_Child2_Object2, "Virtual", "Object 7", 0, 0, 200, 200)
Debug *Object5\Texte
If *Object2\Parent And *Object2\Parent\Name = "Virtual"
Debug *Object2\Parent\Name
EndIf
Debug ""
ForEach MapObject()
Debug MapObject()\Name + " ID " + MapObject()\ID
Next
Debug "Delete ..."
DeleteObject(1)
ForEach MapObject()
Debug MapObject()\Name + " ID " + MapObject()\ID
Next
I am French, I do not speak English.
My apologies for the mistakes.
I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.