[Rename] Object-oriented programming simulation for a virtual object manager

Just starting out? Need help? Post your questions and find answers here.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

I’m having a hard time following you because you’re using language that’s a bit too advanced for me. It’s clear that you’re an expert.
I’m struggling to understand what you mean. Please try to be simpler and clearer—I’m not a professional.

What’s missing from Editors Factory is one specific thing, but I think we might not be talking about the same thing.

To start, I need to create a structure that can manage parent-child relationships (with multiple levels).
Next, I need to figure out how to organize all of this properly, but I’m not sure of the best approach. Maybe I’ll need to use interfaces to do something like this:
*MyObject = CreateObject() ; Here, I’m not sure what to put, maybe:
- CreateObject(Number.i = #Pb_Any, Name.s = "")
or
- NewObject(Number.i = #Pb_Any, Name.s = "")
Then, assigning values could look like this:
*MyObject\Name = "Object #1"
*MyObject\X = 45
*MyObject\Y = 25
*MyObject\Width.i = 100
*MyObject\Height.i = 20
And for methods, we could have something like:
*MyObject\AddChild(Number.i = #Pb_Any, Name.s = "")
*MyObject\DeleteChild(Number.i)
*MyObjectFoundID = *MyObject\FindObjectID(Number.i)
*MyObjectFoundName = *MyObject\FindObjectName(Name.s)
So, I need to use interfaces to do this, right? Are we in agreement?

@SMaag, tell me what you think. Is this a good approach in your opinion?
I think so. And here, this would be true OOP , right?
The usage for the end user doesn’t seem very complicated, does it?

But feedback from other people would also be welcome, just to be sure about what I’m getting into!
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.
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

I don't speek french, so we have to talk in english or german (may be spanish),
let's choose, what is the best for you. I continoue with english.

First I want to describe the problem what I understood you want to do!

1. You want to design a Manager for 2D grafical objects what can handle the basic operations for any 2D grafical object!
That's maybe:
Properties: X,Y, W,H ...
Methodes: move, resize, draw, create, destroy ...

2. You want to implement a hirarchical Object Handling, where an Object can have multiple SubObjects
- that means, that a SubObject has a ParentObject

3. You try to integrate an EventHanling of the Objects (that is what I figured out from Editors factory)
Events can be:
- before drawing, after drawing
- befor moving, after moving
- etc.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

@SMaag, I’m not asking you to speak French :wink:
I’m just asking you to use simpler language because I often have trouble understanding you. I don’t always know where you’re going with your explanations, and sometimes I don’t even know how to respond. Thank you.

1 - Yes, later on, I’ll try to create a very small visual object manager, as a learning exercise. And my goal for it is primarily:

- Create graphical objects on a canvas.
- Draw graphics on them using a procedure dedicated to each object.
- Create and manage a selection system on the canvas to select objects with the mouse.
- Move and resize one or more objects with the mouse on the canvas.

When I’ve done that (which won’t be anytime soon), I’ll add more features.

For now, before doing that, I want to create a virtual object manager , which will serve as the foundation for the visual object manager.

Virtual Object Manager = Data layer for objects. (Creation/deletion, assigning/removing values, etc.)
Visual Object Manager = Managing these objects as graphical elements on a canvas. (Creation / delete, Display, movement, resizing, etc.)

So, before that, I’d like to create the virtual object manager , but in a way that makes it useful for others, so they can use it however they want. I’m not creating it just for myself—I want it to be usable by anyone for any project that requires managing object data.

Maybe later, after all this, I’ll need it again myself. It saves me from having to redo everything from scratch, you see ?
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.
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

ok, thank's! I try to use simpler language!

here is the way how I would start such a Project.
It is only a Braistorming code - not tested.
Only to show my way to start!

Code: Select all

 
DeclareModule Obj
  
  EnableExplicit
  
  Enumeration EObjType
    #Obj_None
    #Obj_Frame
    #Obj_Image
  EndEnumeration
  
  Structure TObjBase
    *pParent.TObj   ; If the Object has a parent, it's the Pointer - otherwise 0
    ObjType.i
    Layer.i         ; The grafical Layer
    Groupe.i        ; No of the Groupe if it's part of an Object Groupe
    Name.s
    X.i
    Y.i
  EndStructure
  
  Structure TObjFrame Extends TObjBase
    W.i
    H.i
    List lstChilds.i()      ; List with the Pointer of Child objects
  EndStructure
  
  Structure TObjImage Extends TObjBase
    PbImgNo.i  
  EndStructure


EndDeclareModule


Module Obj
  
  EnableExplicit
  
  Global NewMap mapObj.i()   ; Map to save all ObjectPointers
  
  Procedure ObjNew(EObjType=#Obj_Frame)
    Protected *Obj.TObjBase
    
    Select EObjType
        
      Case #Obj_Frame
        *Obj = AllocateStructure(TObjFrame)
        If *Obj
          *Obj\ObjType = #Obj_Frame          
        EndIf
        
      Case #Obj_Image
        *Obj = AllocateStructure(TObjImage)
        If *Obj
          *Obj\ObjType = #Obj_Image       
        EndIf
        
    EndSelect
    
    If *Obj
      AddMapElement(mapObj(), Hex(*Obj))  ; Add Object to the Map (the key value)
      mapObj() = *Obj   ;     Set the DataValue of the Map Entry = *Obj
    EndIf
    
    ProcedureReturn *Obj
    
  EndProcedure
  
  ; here we use as PinterType the ObjBase structure becaus all Objects share it!
  Procedure ObjDestroy(*Obj.TObjBase, DestroyChilds=#True)
    Protected res, *child
    
    If *Obj
      res = FindMapElement(mapObj(), Hex(*Obj))
      
      If res    ; The Object exists
        
        If DestroyChilds 
          With *Obj           
            Select \ObjType
                  
              Case #Obj_Frame
                ; to get access to the FrameData, we 
                ; have to define a Pointer to ObjFrame Structre!
                ; because the Pointer to ObjBase and the whole Obj is the same
                ; we can use it as Pointer to whole Object too!
                Protected *objFrame.TObjFrame = *Obj
                
                ForEach *objFrame\lstChilds()
                  *child = *objFrame\lstChilds()
                  ObjDestroy(*child)
                Next
                              
            EndSelect
            
          EndWith    
        EndIf
        
        FreeStructure(*Obj)
        DeleteMapElement(mapObj(), Hex(*Obj))
      EndIf
        
    EndIf
    
    ProcedureReturn *Obj  
  EndProcedure
  
  Procedure Move(*Obj.TObjBase, x, y, Mode=#PB_Relative)
    
    If *Obj
      With *Obj
        If Mode = #PB_Relative
          \X + x
          \Y + y
        Else
          \X = x
          \Y = y
        EndIf        
      EndWith     
    EndIf
    
    ProcedureReturn *Obj  
  EndProcedure
  
  
EndModule

ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

Thank you for your code, SMaag.
But is it really useful to create object types? What would be the concrete purpose of that ?

Are you mixing things up ?
Did you understand what I’m trying to do?

I said that I wanted to first create a virtual object manager , not a visual one.
What would be the point of the Move() function? It has no purpose here!

What is your level of programming? Unlike mine, which isn’t great…
Do you understand the code of Editors Factory ? Would you be able to recreate one, just to know ?
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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6203
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: A virtual object manager code

Post by mk-soft »

@ShadowStorm

I think we are going round in circles here and SMaag knows what it is programming.

The internal functions of Purebasic are also sufficient for your task. So structures and LinkedList

For this you have to learn how structures and LinkedList work in Purebasic.
Then you have to create a structure that can hold the data of your graphics element. Line, box, circle, etc.
With AddElement you then add a new graphic element.
To find the element you have to search with ForEach until the mouse position matches the element.

It is a larger task that can be solved with the internal functions.
You don't need OOP or any object managers. Just a linked list with a suitable structure.

Don't give up and start with the standard functions first.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
miso
Enthusiast
Enthusiast
Posts: 410
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: A virtual object manager code

Post by miso »

@Shadowstorm

My question is, does your current code do what you need? If it does, please don't rewrite it, use it.
In PB you can achieve the same output in multiple ways. If you don't have issues with speed, or something, just use the code you already have.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

miso wrote: Sun Feb 16, 2025 9:22 pm @Shadowstorm

My question is, does your current code do what you need? If it does, please don't rewrite it, use it.
In PB you can achieve the same output in multiple ways. If you don't have issues with speed, or something, just use the code you already have.
My current code is not the best way, as was said earlier, the functions are not listed with the Object, and in addition, the function names will conflict with my future project, I need to review the code, and it allows me to learn, so it's fine :wink:

Thank you for your encouragement :)
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.
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

Are you mixing things up ?
Yes, I'm mixing things: If we talk about the Pointers - I mix the Pointer from the BaseStructure and the derivated Structure.
Both Pointers are the same. That's the trick in Purebasic!
Did you understand what I’m trying to do?
I think so. And I was thinking about that projekt! It is a really good idea!

I said that I wanted to first create a virtual object manager , not a visual one.
What would be the point of the Move() function? It has no purpose here!
Yes an abstract Manager of grafical Objects which can handle all the basic functions like
- Move, Rezize, Select groups, draw, docking objects ...

I asked you a few times to make a description of your problem. Not talk about abstract things like "virtal object Manger".
Im sure we have a very different view on what "virtal object Manger" is!
But until now you could not give us an exact descrption of the problem. We are just speculating what you want to do ecxactly

My answer is according to that what I understand. I described that in a post above!

Once more, let's come back to the beginning and describe what you want to do exactly.
What is your level of programming? Unlike mine, which isn’t great…
Do you understand the code of Editors Factory ? Would you be able to recreate one, just to know ?
I'm an engineer for industrial automation and I'm programmer for industrial software! My programming background is mostly
Pascal and Visual Basic!
Yes, I understand the code of Editors facotry, but my apporach to solve that would be completely different form Editors factory code.

I go totally conform with mk-soft. Linked Lists and Maps are the necessary things.
mk-soft has a similar background like me. We both come from the industrial progamming side. So the way of programming is simliar.
But it's in many ways differnt to that guys comming from game programming.
That means we have a different view on the things and maybe an other way of solution. That's not a better way, it's just a different way!

But there are 1000 ways to solve the problem.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

Yes, I'm mixing things: If we talk about the Pointers - I mix the Pointer from the BaseStructure and the derivated Structure.
Both Pointers are the same. That's the trick in Purebasic!
No, I was talking about mixing up what I wanted to do. I clearly distinguish between what is virtual and what is visual, although, yes, I admit it can also be confusing because both are actually virtual.

I don’t know how to explain it better, so maybe this small code will help.
Later, to use it with my visual object manager, I could, for example, use it like this and do:

Code: Select all

; Visual Objects Handler
; Module, EndModule, structure etc, etc.

; Includes the Virtual Objects Handler module for use with my Visual Objects Handler module

Procedure CreateObject(ObjectNumber.i, X.i, Y.i, Widht.i, Height.i)
  
  ; Création d'un Objet, #PB_Any = ID automatique.
  ; Renvoie un Objet.
  ;
  ; Creates an Object, #PB_Any = Automatic ID.
  ; Returns an Object.
  MyObjectRoot = VOM_CreateObject(ObjectNumber.i = #PB_Any, Name.s "") ; VOM_ = VirtualObjectManager, Evite les conflits de Nom potentiel avec d'autres fonctions existantes.
                                                                       ; VOM_ = VirtualObjectManager, Avoids potential naming conflicts with other existing functions.
  
  ; Si la création de l'Objet a réussi.
  ; Si l'objet existe bien et est initialisé.
  ;
  ; If the Object creation was successful.
  ; If the object exists and is initialized.
  If MyObjectRoot.Init
    
    MyObjectRoot.X = X.i
    MyObjectRoot.Y = Y.i
    
    MyObjectRoot.Width = Widht.i
    MyObjectRoot.Height = Height.i
    
  EndIf
  
  ; ....
  
EndProcedure
------
Yes an abstract Manager of grafical Objects which can handle all the basic functions like
- Move, Rezize, Select groups, draw, docking objects ...
No, that's in the second phase, but yes, in the long term, that's right, in the first phase I want to make the virtual object manager (Data).
Does this mean anything to you, it's an idea of what I think I'd like, no graphics, just data:

I know that this kind of thing is not possible in purebasic:
MyObjectRoot.X = 48
MyObjectRoot.Y = 25

but we'll replace it with this, for example:
MyObjectRoot\X = 48
MyObjectRoot\Y = 25

Code: Select all

; Initialise le gestionnaire d'objet virtuel pour pouvoir l'utiliser.
; On accède aux objets depuis ce gestionnaire.
;
; Initializes the virtual object manager so it can be used.
; Objects are accessed through this manager.

If InitVirtualObjectManager()
  
  ; Création d'un Objet, #PB_Any = ID automatique.
  ; Renvoie un Objet.
  ;
  ; Creates an Object, #PB_Any = Automatic ID.
  ; Returns an Object.
  MyObjectRoot = VOM_CreateObject(ObjectNumber.i = #PB_Any, Name.s "") ; VOM_ = VirtualObjectManager, Evite les conflits de Nom potentiel avec d'autres fonctions existantes.
                                                                       ; VOM_ = VirtualObjectManager, Avoids potential naming conflicts with other existing functions.
  
  ; Si la création de l'Objet a réussi.
  ; Si l'objet existe bien et est initialisé.
  ;
  ; If the Object creation was successful.
  ; If the object exists and is initialized.
  If MyObjectRoot.Init
    
    ; Définit les propriétés de l'objet:
    ;
    ; Defines the object's properties:
    MyObjectRoot.Name = "MyObjectRoot"
    
    MyObjectRoot.X = 48
    MyObjectRoot.Y = 25
    
    MyObjectRoot.Width = 48
    MyObjectRoot.Height = 25
    
  EndIf
  
  ; ----------------
  
  ; Création d'un Objet Enfant, #PB_Any = ID automatique.
  ; Renvoie un Objet.
  ;
  ; Creates a Child Object, #PB_Any = Automatic ID.
  ; Returns an Object.
  MyObjectChild = VOM_CreateObject(ObjectNumber.i = #PB_Any, Name.s "") ; VOM_ = VirtualObjectManager, Evite les conflits de Nom potentiel avec d'autres fonctions existantes.
                                                                        ; VOM_ = VirtualObjectManager, Avoids potential naming conflicts with other existing functions.
  
  ; Si la création de l'Objet a réussi.
  ; Si l'objet existe bien et est initialisé.
  ;
  ; If the Object creation was successful.
  ; If the object exists and is initialized.
  If MyObjectChild.Init
    
    ; Si l'objet parent existe bien et est initialisé.
    ;
    ; If the parent object exists and is initialized.
    If MyObjectRoot.Init
      
      ; Ajout d'un Objet enfant (MyObjectChild) à l'Objet MyObjectRoot.
      ;
      ; Adds a Child Object (MyObjectChild) to the MyObjectRoot Object.
      MyObjectRoot.AddChild(MyObjectChild) ; MyObjectChild est l'enfant de MyObjectRoot.
                                           ; MyObjectChild is the child of MyObjectRoot.
      
      ; Définit les propriétés de l'objet:
      ;
      ; Defines the object's properties:
      MyObjectChild.Name = "Child 1 - MyObjectRoot"
      
      MyObjectChild.X = 10
      MyObjectChild.Y = 15
      
      MyObjectChild.Width = 65
      MyObjectChild.Height = 32
      
    EndIf
    
  EndIf
  
  ; ----------------
  
  ; Création d'un Objet Enfant d'un Enfant, #PB_Any = ID automatique.
  ; Renvoie un Objet.
  ;
  ; Creates a Sub-Child Object, #PB_Any = Automatic ID.
  ; Returns an Object.
  MyObjectSubChild = VOM_CreateObject(ObjectNumber.i = #PB_Any, Name.s "") ; VOM_ = VirtualObjectManager, Evite les conflits de Nom potentiel avec d'autres fonctions existantes.
                                                                           ; VOM_ = VirtualObjectManager, Avoids potential naming conflicts with other existing functions.
  
  ; Si la création de l'Objet a réussi.
  ; Si l'objet existe bien et est initialisé.
  ;
  ; If the Object creation was successful.
  ; If the object exists and is initialized.
  If MyObjectSubChild.Init
    
    ; Si l'objet parent existe bien et est initialisé.
    ;
    ; If the parent object exists and is initialized.
    If MyObjectChild.Init
      
      ; Ajout d'un Objet enfant (MyObjectSubChild) à l'Objet MyObjectChild.
      ;
      ; Adds a Child Object (MyObjectSubChild) to the MyObjectChild Object.
      MyObjectChild.AddChild(MyObjectSubChild) ; MyObjectSubChild est l'enfant de MyObjectChild.
                                               ; MyObjectSubChild is the child of MyObjectChild.
      
      ; Définit les propriétés de l'objet:
      ;
      ; Defines the object's properties:
      MyObjectSubChild.Name = "Child 1 - MyObjectSubChild"
      
      MyObjectSubChild.X = 25
      MyObjectSubChild.Y = 48
      
      MyObjectSubChild.Width = 100
      MyObjectSubChild.Height = 35
      
    EndIf
    
  EndIf
  
  ; --------------------------------------------------------
  
  ; Affichage des objets et de leurs valeurs respectives.
  ; Displays objects and their respective values.
  
  ; On pourrait imaginer une fonction qui liste des objets en fonction de paramètres, par exemple à partir d'un objet parent et de ses enfants et en fonction de leur position X, dans l'ordre croissant ou décroissant.
  ; Properties.i (ID, Name, X, Y, Width, Height, Layer, etc), peut être par exemple #VOM_ExamineNoProperties pour dire que ce paramètre est ignoré.
  ; Options.i (Ascending, Descending, NoCase (If Name))
  ;
  ; We could imagine a function that lists objects based on parameters, for example from a parent object and its children, and based on their X position, in ascending or descending order.
  ; Properties.i (ID, Name, X, Y, Width, Height, Layer, etc), could be for example #VOM_ExamineNoProperties to indicate that this parameter is ignored.
  ; Options.i (Ascending, Descending, NoCase (If Name))
  Object = VOM_ExamineObject(ObjectParent.i = #None, ExamineSubChild.b = #True, level.i = 0, Properties.i = #VOM_ExamineByID, Options.i = #VOM_ExamineAscending) ; Réinitialise l'examination et Renvoie le premier objet examiné en fonction des paramètres indiqués.
                                                                                                                                                                 ; Resets the examination and returns the first examined object based on the specified parameters.
  
  ; Si le paramètre ObjectParent est différent de #None et est un objet valide (Renvoie 0 si ObjectParent n'existe pas), ça peut être n'importe quel objet.
  ; Alors l'examination démarrera à partir d'ici dans la hiérarchie des objets et si ExamineSubChild.b = #True (Si #False, juste le parent est concerné), alors cherchera dans tous les enfants de ce ObjectParent.
  ; Et si Level est supérieur à 0 (car 0 est le parent actuel et tous ses enfants), alors examine les enfants des enfants en fonction de la profondeur de recherche (Level).
  ; Par exemple, si 1, cherchera dans tous les enfants des enfants du parent, si 2 alors cherchera dans tous les enfants des enfants des enfants du parent, etc.
  ;
  ; If the ObjectParent parameter is not #None and is a valid object (Returns 0 if ObjectParent does not exist), it can be any object.
  ; Then the examination will start here in the object hierarchy, and if ExamineSubChild.b = #True (If #False, only the parent is concerned), it will search through all the children of this ObjectParent.
  ; And if Level is greater than 0 (since 0 is the current parent and all its children), it examines the children of the children based on the search depth (Level).
  ; For example, if 1, it will search through all the children of the children of the parent, if 2 then it will search through all the children of the children of the children of the parent, etc.
  
  ; Exemple: (Dans cet exemple, si ExamineSubChild.b = #True, alors l'objet MyObjectSubChild sera pris en compte dans l'examination, sinon non.)
  ; Example: (In this example, if ExamineSubChild.b = #True, then the MyObjectSubChild object will be included in the examination, otherwise not.)
  MyObject = VOM_ExamineObject(ObjectParent.i = MyObjectChild, ExamineSubChild.b = #True, level.i = 4, "X", #Descending) ; Ici il n'y a pas 4 niveaux, donc examinera tous les niveaux qui existent mais jusqu'à 4 maximum.
                                                                                                                         ; Here there are not 4 levels, so it will examine all existing levels but up to a maximum of 4.
  
  While MyObject
    
    Debug "Object Name: " + Object.Name
    Debug "Object ID: " + Object.ID
    Debug "Object X: " + Object.Name
    Debug "Object Y: " + Object.Name
    Debug "Object Width: " + Object.Width
    Debug "Object Height: " + Object.Height
    Debug  "-----------------------------"
    
    Object = VOM_NextObject() ; Renvoie le prochain objet examiné.
                              ; Returns the next examined object.
    
  Wend
  
  ; --------------------------------------------------------
  
  ; Recherche un Objet quelconque portant ce nom.
  ; Renvoie un Objet.
  ;
  ; Searches for any Object with this name.
  ; Returns an Object.
  Object = VOM_FindObjectByName(ObjectName.s)
  
  If Object.X = 45
    ...
  EndIf
  
  ; Recherche un Objet spécifique depuis son numéro d'identification.
  ; Renvoie un Objet.
  ;
  ; Searches for a specific Object by its identification number.
  ; Returns an Object.
  Object = VOM_FindObjectByID(ObjectID.i)
  
  If Object.Width = 200
    ...
  EndIf
  
  ; Recherche un Objet très spécifique portant ce numéro d'identification ainsi que ce Nom.
  ; Renvoie un Objet.
  ;
  ; Searches for a very specific Object with this identification number and this Name.
  ; Returns an Object.
  Object = VOM_FindObjectByIDAndName(ObjectName.s, ObjectName.s)
  
  If Object.Width = 50 And Object.Height = 75
    ...
  EndIf
  
  
  
  ; Renvoie l'objet Parent de l'objet indiqué ou 0 si il n'y en a pas.
  ; Si Object = MyObjectRoot, renverra donc MyObjectRoot par exemple, si c'est MyObjectSubChild, renverra donc MyObjectChild.
  ;
  ; Returns the Parent object of the specified object, or 0 if there is none.
  ; If Object = MyObjectRoot, it will return MyObjectRoot, for example. If it's MyObjectSubChild, it will return MyObjectChild.
  ParentObject = VOM_FindObjectParent(Object)
  
  If ParentObject.Name = "Child 1 - MyObjectRoot"
    ...
  EndIf
  
  
  
  ; Renvoie le parent racine d'un objet (Le tout premier).
  ; Renvoie un Objet.
  ;
  ; Returns the root parent of an object (the very first one).
  ; Returns an Object.
  MyObjectRootParent = VOM_FindObjectRootParent(MyObjectSubChild) ; Renvoie: MyObjectRoot.
                                                                  ; Returns: MyObjectRoot.
  
  
  
  ; Détruit un Objet et éventuellement tous ses enfants.
  ; Si DeleteChild.b = #True, tous les enfants seront aussi supprimés, sinon ils seront placés dans le parent de l'objet (Object) précédent.
  ; Si pas de parent, ils n'auront alors pas de parent = Orphelin (Note: Un objet créé par défaut est orphelin !).
  ; Si un objet enfant est le parent d'autres objets enfants, alors les enfants de cet objet enfant (Parent) garderont leur parent qui est l'objet enfant de base.
  ;
  ; Destroys an Object and optionally all its children.
  ; If DeleteChild.b = #True, all children will also be deleted; otherwise, they will be placed in the previous parent of the Object.
  ; If there is no parent, they will have no parent = Orphan (Note: An object created by default is orphaned!).
  ; If a child object is the parent of other child objects, then the children of that child object (Parent) will keep their parent, which is the base child object.
  VOM_DeleteObject(Object.i, DeleteChild.b = #True)
  
  
EndIf
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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6203
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: A virtual object manager code

Post by mk-soft »

You must adhere to the syntax of PureBasic. Structure access is not "." but "\" and you have to use a *pointer for this
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

mk-soft wrote: Mon Feb 17, 2025 5:02 pm You must adhere to the syntax of PureBasic. Structure access is not "." but "\" and you have to use a *pointer for this
I know that, and I've said it to show roughly what I want to do !
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.
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

@Smaag,

Okay, so from what I’ve understood, the issue that’s bothering you is that the functions aren’t listed with the object in IntelliSense . So, all I need to do is add an interface and set everything up properly, and then you’ll be happy because IntelliSense will work !
Yes, I can do that; I’ve understood how to proceed !

If not, do you have an idea for the pseudo code I made ?, because the problem with an interface
is that I can only list the functions with the object, not the properties !

Otherwise another original idea I had if what I asked can not be done, why not a kind of:

*MyObject.StructureObject = InitObject()

*MyObject\PropertiesLength = 45
*MyObject\Methods\SetX(24)
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.
SMaag
Enthusiast
Enthusiast
Posts: 302
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: A virtual object manager code

Post by SMaag »

- If I need such a program I would start my own project because I want to have a similar style of all my codes.
But I copy good concepts from other programmers too.

The same you should do:! Code it in your own style, so you can understand an mange the code.

I see from the post before, you have problems to understand my way. You are not able to copy ideas from the examples and
integrate the conecpts in your way of coding.

Maybe you should start at a lower level! Get a deeper understanding of lists, maps and pointers.
If you exactly know how it works, then start again.

Then if you have an excactly defined problem, we may help you.
But we can not write the software for you!
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

I know you can’t code for me, and you’re right!
We all have our own way of coding.

And yes, I still need help because the AI is still struggling to keep up.

For now, as you can see, I’m experimenting without really understanding how it works because it’s very complicated. I’ve built two small pieces of code based on an example from the help documentation, but I still can’t get it to work !

Code: Select all

Interface InterfaceObject
  GetPerimeter.i()
  GetSurface.i()
  SetLength.i(Valeur)
  SetWidth.i(Valeur)
  Destroy.i()
EndInterface

Structure ObjectProperties
  
  *VirtualTable ; Virtual Table
  
  Length.i
  Width.i
  
EndStructure

Structure ObjectFields
  
  Methode.InterfaceObject
  Properties.ObjectProperties
  
EndStructure

Declare.i GetPerimeter(*this.ObjectProperties)
Declare.i GetSurface(*this.ObjectProperties)
Declare.i SetLength(*this.ObjectProperties, Valeur)
Declare.i SetWidth(*this.ObjectProperties, Valeur)
Declare.i Destroy(*this.ObjectProperties)
  
DataSection
  Class:
  Data.i @GetPerimeter()
  Data.i @GetSurface()
  Data.i @SetLength()
  Data.i @SetWidth()
  Data.i @Destroy()
EndDataSection

Procedure.i InitObject(Length=0, Width=0)
  
  ; Définie le Type du Pointeur *Object.
  ; Ici *Object est un pointeur de type ObjectProperties, il vaux 0 actuellement ici et c'est normale.
  Protected *Object.ObjectProperties
  
  ; Maintenant *Object a ça propre structure à lui: ObjectProperties.
  ; *Object recois l'adresse de la nouvelle structure dynamique, zéro sinon.
  *Object = AllocateStructure(ObjectProperties)
  
  ; Si le pointeur *Object est bien ititialisé.
  If *Object
    
    ; La Table Virtuel de *Object reçois l'adresse de l'étiquette "Class" ou sont référencer toutes les adresses des procédure (Méthodes).
    *Object\VirtualTable = ?Class
    
  EndIf
  
  ProcedureReturn *Object
  
EndProcedure


Procedure GetPerimeter(*this.ObjectFields)
  ProcedureReturn (*this\Properties\Length + *this\Properties\Width) * 2
EndProcedure

Procedure GetSurface(*this.ObjectFields)
  ProcedureReturn *this\Properties\Length * *this\Properties\Width
EndProcedure

Procedure SetLength(*this.ObjectFields, Valeur)
  *this\Properties\Length = Valeur
EndProcedure

Procedure SetWidth(*this.ObjectFields, Valeur)
  *this\Properties\Width = Valeur
EndProcedure

Procedure Destroy(*this.ObjectFields)
  FreeStructure(*this)
EndProcedure


; How to use it

MyField.InterfaceObject = InitObject()

MyObject.ObjectFields
MyObject\Methode = MyField.InterfaceObject

MyObject\Properties\Length = 45
MyObject\Properties\Width = 25

Debug MyObject\Properties\Length
Debug MyObject\Properties\Width

Debug "-------"

Debug "Perimeter is  " + MyObject\Methode\GetPerimeter()
Debug "Surface is  "  + MyObject\Methode\GetSurface()

Debug ""

;Let's modify some values
MyObject\Methode\SetLength(40)
MyObject\Methode\SetWidth(20)
Debug "Perimeter is  " + MyObject\Methode\GetPerimeter()
Debug "Surface is  "  + MyObject\Methode\GetSurface()

MyObject\Methode\Destroy()
Debug ""

Code: Select all

Structure StructureProperties
  
  Length.i
  Width.i
  
  *VirtualTable ; Data Section Virtual Table.
  
EndStructure

Declare.i Perimeter(*this.StructureProperties)
Declare.i Surface(*this.StructureProperties)
Declare.i Length(*this.StructureProperties, Valeur)
Declare.i Width(*this.StructureProperties, Valeur)
Declare.i Destroy(*this.StructureProperties)
  
Interface InterfaceMethode
  Perimeter.i()
  Surface.i()
  Length.i(Valeur)
  Width.i(Valeur)
  Destroy.i()
EndInterface

Structure StructureObject
  
  *Object
  Methods.InterfaceMethode      
  Properties.StructureProperties
  
EndStructure

NewMap MapObject.i()

DataSection
  Class:
  Data.i @Perimeter()
  Data.i @Surface()
  Data.i @Length()
  Data.i @Width()
  Data.i @Destroy()
EndDataSection

Procedure.i InitObject()
  
  Protected *StructureProperties.StructureProperties
  Protected *StructureObject.StructureObject
  
  *StructureProperties = AllocateMemory(SizeOf(StructureProperties))
  
  If *StructureProperties
    *StructureProperties\VirtualTable = ?Class
    
    *StructureProperties\Length = Length
    *StructureProperties\Width = Width
    
    *StructureObject = AllocateMemory(SizeOf(StructureObject))
    
    If *StructureObject
      *StructureObject\Object = *StructureProperties
    EndIf
    
  EndIf
  
  ProcedureReturn *StructureObject
  
EndProcedure


Procedure.i Perimeter(*this.StructureProperties)
  ProcedureReturn (*this\Length + *this\Width) * 2
EndProcedure

Procedure.i Surface(*this.StructureProperties)
  ProcedureReturn *this\Length * *this\Width
EndProcedure

Procedure.i Length(*this.StructureProperties, Valeur)
  *this\Length = Valeur
EndProcedure

Procedure.i Width(*this.StructureProperties, Valeur)
  *this\Width = Valeur
EndProcedure

Procedure.i Destroy(*this.StructureProperties)
  FreeMemory(*this)
EndProcedure


*MyObject.StructureObject = InitObject()

*MyObject\Properties\Length = 45
Debug *MyObject\Properties\

*MyObject\Methods\Destroy()
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.
Post Reply