[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

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

Post by ShadowStorm »

Hi,

I’ve started creating a virtual object manager, and it has already required a lot of work, with the help of AI for repetitive tasks and some minor things. There’s already quite a bit of code to manage, so I’ve split it into different files, and even then, it’s not always easy.

The purpose of this code is to create virtual objects, manipulate them, assign values to them, and also retrieve those values. The code is too long, so it’s available for free download.

It’s all well-documented in both French and English!
It’s not yet 100% complete, but it’s already pretty good.

Some functions are not yet usable and don’t serve any purpose right now, but they will later.

This code is probably not very optimized, but I’m open to improvements and additions.
Why am I doing this?

I have a project to recreate a very small Editors Factory , which will be called Visual Object Manager or something like that. I’ll do it all by myself with my own means, with the help of AI and anyone who wants to contribute, and it will use this module.

I want to separate things: a Data (Virtual) part and a Real (Visual) part. The visual side will manipulate data (objects).
I’m not very skilled at coding; I do what I can. It’s not easy, especially with many files and lots of code.

And I’m not claiming that I’ll recreate Editors Factory —no, impossible! But I’ll try to recreate a small part of it, and we’ll see how far I can go.
I’ll try to handle the creation, display, movement, and resizing of objects, but even that will be quite difficult.

But before that, I want to fine-tune this module and make it optimal and complete. Plus, this module could be reused by others or by me in other projects!
Feel free to share your thoughts.

Later, I might consider putting a document online so that some people can improve the code, give feedback, etc. That could be pretty cool, right?

Some function names, not all of them !:

Code: Select all

; Checks if an object exists in the Map.
Procedure.b IsObject(ObjectNumber.i)

; Creates a new object.
Procedure.i CreateObject(ObjectNumber.i, X.i, Y.i, Width.i, Height.i)

; Creates a random object name.
Procedure.s CreateRandomObjectName()

; Deletes an object if it exists.
Procedure.b DeleteObject(ObjectNumber.i)

; Selects the object.
Procedure.b SelectObject(ObjectNumber.i)

; Unselects the object.
Procedure.b UnselectObject(ObjectNumber.i)

; Disables the object.
Procedure.b DisableObject(ObjectNumber.i)

; Enables the object.
Procedure.b EnableObject(ObjectNumber.i)

; Hides the object.
Procedure.b HideObject(ObjectNumber.i)

; Shows the object.
Procedure.b ShowObject(ObjectNumber.i)

; Returns the number of objects that have been created.
Procedure.i CountObject()

; Examines or reexamines all objects from the beginning of the object list (system).
Procedure.i ExamineObjects()

; Moves the pointer one position forward in the object list and returns the next object number.
Procedure.i NextObject()

Code: Select all

; Gets the type of the object.
Procedure.s GetObjectType(ObjectNumber.i)

; Gets the name of the object.
Procedure.s GetObjectName(ObjectNumber.i)

; Returns the unique identifier of the object.
Procedure.i GetObjectID(ObjectNumber.i)

; Gets the X position of the object.
Procedure.i GetObjectX(ObjectNumber.i)

; Gets the Y position of the object.
Procedure.i GetObjectY(ObjectNumber.i)

; Gets the mouse X position on the object.
Procedure.i GetObjectMouseX(ObjectNumber.i)

; Gets the mouse Y position on the object.
Procedure.i GetObjectMouseY(ObjectNumber.i)

; Gets the width of the object.
Procedure.i GetObjectWidth(ObjectNumber.i)

; Gets the height of the object.
Procedure.i GetObjectHeight(ObjectNumber.i)

Code: Select all

; Sets the name of the object.
Procedure.b SetObjectName(ObjectNumber.i, Name.s)

; Sets the type of the object.
Procedure.b SetObjectType(ObjectNumber.i, Type.s)

; Sets the X position of the object.
Procedure.b SetObjectX(ObjectNumber.i, X.i)

; Sets the Y position of the object.
Procedure.b SetObjectY(ObjectNumber.i, Y.i)

; Sets the mouse X position on the object.
Procedure.b SetObjectMouseX(ObjectNumber.i, MouseX.i)

; Sets the mouse Y position on the object.
Procedure.b SetObjectMouseY(ObjectNumber.i, MouseY.i)

; Sets the width of the object.
Procedure.b SetObjectWidth(ObjectNumber.i, Width.i)

; Sets the height of the object.
Procedure.b SetObjectHeight(ObjectNumber.i, Height.i)

Link:
https://drive.google.com/file/d/188eVap ... sp=sharing
Last edited by ShadowStorm on Sun Feb 23, 2025 5:06 pm, edited 1 time in total.
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 »

It's really looking like AI!
Creating a lot of text. Making easy things complicated!
It looks like a try to implement a little bit OOP feeling but it isn't!

A much easier way to do:
1. Create a Strutre with your need Object Data
2. Use the PB's List() and/or Map() to List, Search, Create and Destroy Objects
Then you do not need the help of AI and you do not need this crazy Code overhead.
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: A virtual object manager code

Post by NicTheQuick »

I don't understand the use case. Can you make an example that explains why one would need it?
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 561
Joined: Tue Jan 04, 2011 6:21 pm

Re: A virtual object manager code

Post by SPH »

Code: Select all

Procedure destroy(i)
  i=0
  Debug i
EndProcedure

destroy(1)
  
  

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

[Work in Progress] Data Management in Virtual Objects

This module is not finished yet—there’s still work to be done. And no, it wasn’t created by AI—let’s not exaggerate, I’m the one who developed it!

That said, I did use AI as a tool: it helped me generate redundant code, correct French grammar, translate and add English comments, and improve the code when needed. I’m completely transparent about it!

I don’t see the issue—AI doesn’t judge, it helps without complaining, and it does what we ask within its current (still limited) capabilities. But it’s already an amazing tool for those who know how to use it, and it’s only going to get better. Thanks to it, I’ll be able to complete projects more easily in the future… if I survive!

📌 What’s This Module For?
It’s designed to manage data within virtual objects. For example, it could be used to handle custom Gadgets in a Canvas or manage objects within an interactive space.

So yeah, it’s a data management tool for virtual objects. Pretty straightforward, and I think it could be useful for some projects!

🛠 Feedback Is Welcome!
Criticism? Sure—but keep it constructive and objective! I’ve spent a lot of time refining and improving this module, and no, it wasn’t built in a day.

In fact, I already have a future project lined up that will use this module to make my life easier. Stay tuned! 😉
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.
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: A virtual object manager code

Post by Denis »

Salut ShadowStorm,

no chance to get a chm help file with more explanations ?
A+
A+
Denis
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

Denis wrote: Thu Feb 13, 2025 6:52 am Salut ShadowStorm,

no chance to get a chm help file with more explanations ?
A+
Hello Denis,
For now, this project is still in its early stages and not developed enough to consider turning it into a CHM file. It’s possible that it might end up being useless for users, or that my code is poorly designed. However, the code is already well-documented with plenty of comments. I’m currently working on improving it by adding more explanations. Once the project is more mature and better organized, I might consider creating some documentation. But just to make sure we’re on the same page, did you understand what it’s about ?
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 »

Let me do some contructive criticism:

1. It looks like it should simulate a kind of Object orientated programming!
If like to use OOP, why you do not do real OOP with Interfaces? In my opinion the better solution.

2. Splittting the Code over some files makes it unreadable and it was hard to do a Stringsearch to find where the names of
functions, variables are used.

3. Object management with a List combiened with an index Map will do the same with less code and easier to unterstand.


My opinion form sofware arichetcure side is:
If you decide to use OOP concept, than use it like OOP is normally done. Not a try of simulation how you do!
If you deicde not to use OOP, then use an other concept. Maybe that with List and Map. If you don't know how to do, I guess
we can give you examples!
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: A virtual object manager code

Post by Denis »

ShadowStorm wrote: Thu Feb 13, 2025 8:12 am Hello Denis,
For now, this project is still in its early stages and not developed enough to consider turning it into a CHM file. It’s possible that it might end up being useless for users, or that my code is poorly designed. However, the code is already well-documented with plenty of comments. I’m currently working on improving it by adding more explanations. Once the project is more mature and better organized, I might consider creating some documentation. But just to make sure we’re on the same page, did you understand what it’s about ?
I think so.
A+
Denis
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

SMaag wrote: Thu Feb 13, 2025 10:13 am Let me do some contructive criticism:

1. It looks like it should simulate a kind of Object orientated programming!
If like to use OOP, why you do not do real OOP with Interfaces? In my opinion the better solution.

2. Splittting the Code over some files makes it unreadable and it was hard to do a Stringsearch to find where the names of
functions, variables are used.

3. Object management with a List combiened with an index Map will do the same with less code and easier to unterstand.


My opinion form sofware arichetcure side is:
If you decide to use OOP concept, than use it like OOP is normally done. Not a try of simulation how you do!
If you deicde not to use OOP, then use an other concept. Maybe that with List and Map. If you don't know how to do, I guess
we can give you examples!
Hello SMaag,

Thank you for your constructive criticism, which is very much appreciated because it allows for better exchanges and makes the discussion more enjoyable than purely negative remarks. :):wink:

I must admit I’m having trouble understanding what you mean—I’m a bit confused.:?

I know what OOP (object-oriented programming) is, and maybe that’s what I’m doing without realizing it. I’m not specifically trying to do OOP, well… I don’t think so. My code aims to create something you’re already familiar with. If you think my approach is flawed, no problem, I respect your opinion.:wink:

Perhaps we’re not understanding each other well?

Are you familiar with Editors Factory ? It works somewhat like that, except that for now, I’m only focusing on the "Data" part.
This module will make my life much easier when I use it in the next module.

You mentioned that it’s difficult to find things because of the large number of files. I understand your point, but personally, it’s much easier for me to work this way. Otherwise, I waste a lot of time scrolling through a single file with my mouse wheel.:lol:

If I understood correctly, you’re suggesting that I should share my code in a single file. I’ll take note of your suggestion, thank you.

OOP with interfaces—I can do without them because I don’t know this concept and find it complicated.
Perhaps you could show me how you would approach it, without redoing everything? A small example would be perfect.
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 »

Here I have a simple ObjectManager Demo with Objectdata stored in a Map (Key=ID)
and for handling a second Key I use a seperate index Map mapIdxName.i() where the key = Name
this mapIdxName.i is an Integer because as value it stores the *Obj, so we can get the *Obj Pointer
later ByName or ByID

Code: Select all


; Simple Object Manager Demo, with two Keys [ID, Name]


DeclareModule Obj
  
  EnableExplicit 
  
  Structure TObj
    _Name.s       ; use '_' to see it is not allowed to change if once set
    _ID.i
    X.i
    Y.i
    W.i
    H.i
    Color.l
    Flags.i 
    ; etc.
    ; and all your other Object Data
  EndStructure
  
  Declare NewObj(Name.s="", X=0, Y=0, W=0, H=0, Color = 0, Flags =0)
  Declare DeleteObj(Name.s)
  Declare ObjByName(Name.s)
  Declare ObjByID(ID)
  
  Global NewMap mapObj.TObj()

EndDeclareModule


Module Obj
  
  EnableExplicit 
  
  ; a second Index by Name
  Global NewMap mapIdxName.i()  ; we save the ObjectPointer to search it by ID  
    
  Procedure NewObj(Name.s="", X=0, Y=0, W=0, H=0, Color = 0, Flags =0)
    Protected *Obj, res
    Static NewID = 1  
    
    res = FindMapElement(mapIdxName(), Name)
    
    If res ; Object is existing
      MessageRequester("Object handling!", "The Object '" +Name +"' already exists!")
      ProcedureReturn 0
      
    Else
      ; add the Object to the list and index Maps
      
      *Obj = AddMapElement(mapObj(), Hex(NewID))  ; use the _ID as the basic Key
      If *Obj 
        With mapObj()
          \_ID = NewID      
          \_Name =Name  
          \X = X
          \Y = X
          \W = X
          \H = X
          \Color = Color
          \Flags = Flags
         
          AddMapElement(mapIdxName(), \_Name)  ; an index Table to find Objects fast by Name
          mapIdxName() = *Obj
        EndWith
        NewID + 1

       ProcedureReturn *Obj ; return ObjPointer if succeed
        
      EndIf
      
    EndIf
     
     ProcedureReturn 0
  
  EndProcedure
    
  Procedure ObjByName(Name.s)
    Protected res, *Obj
    
    Debug "ObjByName : " + Name
    res = FindMapElement(mapIdxName(),Name)
    If res
      *Obj = mapIdxName()
      Else
      
      Debug "ObjectByName not found"
    EndIf
    
     ProcedureReturn *Obj
  EndProcedure
  
  Procedure ObjByID(ID)
    Protected *Obj
    
    *Obj = FindMapElement(mapObj(), Hex(ID))
     ProcedureReturn *Obj
  EndProcedure
  
  Procedure DeleteObj(Name.s)
    Protected *Obj.TObj
    
    *Obj = ObjByName(Name)  
    If *Obj
      Debug "Delete : " + *Obj\_Name
      Debug "ID = " + *Obj\_ID
      DeleteMapElement(mapIdxName(), Name) ; *Obj\Name)
      DeleteMapElement(mapObj(), Hex(*Obj\_ID))       ; Delete Object in the ObjectList  
      ProcedureReturn #True
    Else 
      Debug "Object to delete not found : " + Name
    EndIf
    ProcedureReturn #False    
  EndProcedure

EndModule

; TestCode

EnableExplicit
UseModule Obj

Define I
Define *MyObj.TObj

For I = 1 To 10
  *MyObj = NewObj("MyObj_"+I, 10+I*5, 10+I*5, 50, 50, #Black)
Next


ForEach mapObj()
  Debug mapObj()\_Name + " : " + mapObj()\_ID  
Next

; Now try to add existing object again

; *MyObj = NewObj("MyObj_1", 10+I*5, 10+I*5, 50, 50, #Black)

; now find an Object by Name

Debug ""
Debug "Now find Object by Name"
*MyObj = ObjByName("MyObj_8")
Debug *MyObj\_Name

Debug "delete an Object"
DeleteObj("MyObj_1")

Debug ""
ForEach mapObj()
  Debug mapObj()\_Name + " : " + mapObj()\_ID  
Next

*MyObj = ObjByID(5)
*MyObj\X = 55
*MyObj\y = 56

Debug ""
ForEach mapObj()
  With mapObj()
    Debug \_Name + " : X= " + Str(\X) + " : Y= " + Str(\Y) 
  EndWith
Next



Last edited by SMaag on Thu Feb 13, 2025 7:30 pm, edited 1 time in total.
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 know what OOP (object-oriented programming) is, and maybe that’s what I’m doing without realizing it. I’m not specifically trying to do OOP, well… I don’t think so. My code aims to create something you’re already familiar with. If you think my approach is flawed, no problem, I respect your opinion.:wink:
All your Getter and Setter Functions are the same as Properties of an Object! So you simulate an Object's Property Interface with all your Getter and Setter functions.

Your ResetObjectSaveEvent() is same as an Object's Methode!
OOP with interfaces—I can do without them because I don’t know this concept and find it complicated.
Perhaps you could show me how you would approach it,
In OOP there are Properties and Methodes. Generally it's the same, a Procedure or a Function.
It's called Property if you have the 2 functions setter and a getter. It's called Methode if you have only one function!

In an Interface you collect all the Getter, Setter Functions and the Methodes.
If you do so, the IDE will show you up all with the intellisense

Code: Select all

  Interface Obj 
    ; Getter
    GetObjectName()   
    GetObjectType()
    ;setter
    SetObjectName(NewName$)
    SetObjectType(NewType)
    ; Methodes
    MyObjectMethode1(Parameter)
    
  EndInterface

But real OOP need's a little more. You have to do a 'mapping' of all the functions in the Interface. You have to map this virtual functions to the real functions you code in the Modul part. This is done with the VT (virtual address Table). The virtual Address Table contains for each virtual function in the Interface, the ProcedurePointer of the function you coded in the Modul part.
Because PB do not support native OOP you have to generate the virtual address tabel by yourselfe.

For OOP the best is to have a BasceClass what implements all that basic OOP Stuff. There is some on the forum.

Here a very good one, with a lot of functionality, but difficult to understand for beginners.
http://www.purebasic.fr/english/viewtop ... 12&t=64305

I did one with little less functionalty but easier to understand. But I tested it on windows only. Maybe there will be a problem
with the iUnknown because this is Windows special!

Interface IClass Extends IUnknown ; If there are problems at Linux or MacOs remove the Extends IUnkonwn

https://github.com/Maagic7/PureBasicFra ... ass_OOP.pb
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: A virtual object manager code

Post by ShadowStorm »

@SMaag,

Thank you for your time and your example.
The problem is that I can't figure it out.

Is your code really better than mine?
I mean, do I have to do it the way you did it?

Your code is too indigestible for me, sorry :(

I have my own way of coding, I try to make it clean and clear, I don't understand your code.

So let's forget about the interface ^^.
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 »

Is your code really better than mine?
Better is a point of the view! It is much shorter. Time to code it 15..20min

You said your code was a huge work, what I can imagen.

The process it's always the same with Objects, does not matter what kind of software you write.
You have to create an Object, delete it, step trough all Objects. Find Object By one ore more keyvalue.
Change Object Values. - There a 1000s of ways to do that!
I mean, do I have to do it the way you did it?
That's your choice. It's only to show how my way would be!
Your code is too indigestible for me, sorry :(
1. I list all the ObjectData in a Map. mapObj() with the Key=Obj\ID
I did an automatic ObjectID counter, just to have an unique ID. Possible to do this in an other way!

2. to show you how to handle more KeyValues I added a second IndexMap mapIdxName() Key=Obj\Name

3. I coded some Functions to create a New Object, Delete Object,
GetBack Objektpointer by ObjID or ObjName.

So if you can search for objects by Name or ID and get back the Pointer.
You can delete all your getter setter ... Functions, because you do not need it! You have direct access to the Object Values.
I have my own way of coding.
Yes, everyone of us has it's own way and that's good!
I think your way of the Object Manger is not an intersting thing for the most progammers here. ! Let's look at the other comments. There was no one who unterstood what you want to do with that! I think really no one of us would have a similar idea. It don't solve a common problem in better way as we know.

You described in an enthusiastic way your huge work. I can understand that you are excited about it!

But my opinion is completely different from yours. It was a great traning job to go one step ahead. Now redo from start! For me your code has no practical value. It's to long. It's to much work to code it. It simulates a kind of OOP with all this getter, setter and Interface functions but it isn't OOP. You can't use IDE's intellisense to list up you interface. etc. etc. etc.

Sorry, I just share my view of the things to help you, not to blame.
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: A virtual object manager code

Post by mk-soft »

Without OOP but with Object.

It is too complex and makes no sense.
But shows that you can manage different substructures with Maps and AllocateMemory in an Object Structure.

Update

Code: Select all

;-TOP

Enumeration 1
  #ObjectWindow
  #ObjectTextGadget
  #ObjectStringGadget
EndEnumeration

Structure udtObjectWindow
  ID.i
  Caption.s
  x.i
  y.i
  Width.i
  Height.i
  Flags.i
EndStructure

Structure udtObjectGadget
  ID.i
  Caption.s
  x.i
  y.i
  Width.i
  Height.i
  Flags.i
  Value1.i
  Value2.i
  ;
EndStructure

Structure udtObject
  Type.i
  ID.i
  ObjectName.s
  *Parent.udtObject
  StructureUnion
    *AnyObject
    *Window.udtObjectWindow
    *Gadget.udtObjectGadget
  EndStructureUnion
EndStructure

Global NewMap Object.udtObject()

Procedure CreateObject(ParentID, ID, Type, Name.s, x, y, Width, Height, Flags=0, Value1= 0, Value2=0) ;, etc
  Protected *Parent.udtObject
  Select Type
    Case #ObjectWindow
      AddMapElement(Object(), Str(id))
      Object()\ID = ID
      Object()\Type = #ObjectWindow
      Object()\ObjectName = "Window"
      Object()\Parent = 0
      
      Object()\Window = AllocateStructure(udtObjectWindow)
      Object()\Window\Caption = Name
      Object()\Window\x = x
      Object()\Window\x = y
      Object()\Window\x = Width
      Object()\Window\x = Height
      Object()\Window\Flags = Flags
      
      ;TODO Create Window
      
      ProcedureReturn @Object()
      
    Case #ObjectTextGadget
      If FindMapElement(Object(), Str(ID))
        ProcedureReturn 0
      EndIf
      If Not FindMapElement(Object(), Str(ParentID))
        ProcedureReturn 0
      EndIf
      *Parent = Object()
      If *Parent\Type <> #ObjectWindow
        ProcedureReturn 0
      EndIf
      AddMapElement(Object(), Str(ID))
      Object()\Type = #ObjectTextGadget
      Object()\ID = ID
      Object()\ObjectName = "Text"
      Object()\Parent = *Parent
      
      Object()\Gadget = AllocateStructure(udtObjectGadget)
      Object()\Gadget\Caption = Name
      Object()\Gadget\x = x
      Object()\Gadget\x = y
      Object()\Gadget\x = Width
      Object()\Gadget\x = Height
      Object()\Gadget\Flags = Flags
      
      ;TODO Create TextGadget
      
      ProcedureReturn @Object()
      
    Case #ObjectStringGadget
      If FindMapElement(Object(), Str(ID))
        ProcedureReturn 0
      EndIf
      If Not FindMapElement(Object(), Str(ParentID))
        ProcedureReturn 0
      EndIf
      *Parent = Object()
      If *Parent\Type <> #ObjectWindow
        ProcedureReturn 0
      EndIf
      AddMapElement(Object(), Str(ID))
      Object()\Type = #ObjectStringGadget
      Object()\ID = ID
      Object()\ObjectName = "String"
      Object()\Parent = *Parent
      
      Object()\Gadget = AllocateStructure(udtObjectGadget)
      Object()\Gadget\Caption = Name
      Object()\Gadget\x = x
      Object()\Gadget\x = y
      Object()\Gadget\x = Width
      Object()\Gadget\x = Height
      Object()\Gadget\Flags = Flags
      
      ;TODO Create StringGadget
      
      ProcedureReturn @Object()
    
  EndSelect
  
EndProcedure

Procedure DeleteObject(ID)
  If FindMapElement(Object(), Str(ID))
    PushMapPosition(Object())
    ForEach Object()
      If Object()\Parent
        If Object()\Parent\ID = ID
          FreeStructure(Object()\AnyObject)
          DeleteMapElement(Object())
        EndIf
      EndIf
    Next
    PopMapPosition(Object())
    FreeStructure(Object()\AnyObject)
    DeleteMapElement(Object())
  EndIf
  
EndProcedure

;----

*obj1.udtObject = CreateObject(0, 1, #ObjectWindow, "WinTitle", 0, 0, 200, 200)
*obj2.udtObject = CreateObject(1, 2, #ObjectTextGadget, "Input", 10, 10, 180, 25)
*obj3.udtObject = CreateObject(1, 3, #ObjectStringGadget, "", 10, 45, 180, 25)

*obj4.udtObject = CreateObject(0, 4, #ObjectWindow, "Win2", 0, 0, 200, 200)
*obj5.udtObject = CreateObject(4, 5, #ObjectTextGadget, "Input", 10, 10, 180, 25)
*obj6.udtObject = CreateObject(4, 6, #ObjectStringGadget, "", 10, 45, 180, 25)

Debug *obj5\Gadget\Caption
If *obj2\Parent And *obj2\Parent\ObjectName = "Window"
  Debug *obj2\Parent\Window\Caption
EndIf

Debug ""
ForEach Object()
  Debug Object()\ObjectName + " ID " + Object()\ID
Next

Debug "Delete ..."
DeleteObject(1)

ForEach Object()
  Debug Object()\ObjectName + " ID " + Object()\ID
Next

CallDebugger
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
Post Reply