But you do not need
*Methods.ObjectMethods
The Methodes are all listed in the Interface, so you do not need any extras for this!
I modified your code a little to show the difference between Module call and Interface call
Code: Select all
DeclareModule MyObj
; Code créer par Dieppedalle David avec l'aide de l'IA, le 22/02/2025.
; Code created by Dieppedalle David with the help of AI, on 22/02/2025.
; ======================================================
; Structure des propriétés de l'Objet.
; Structure of the Object's properties.
; ======================================================
Structure ObjectProperties
ID.i ; L'ID de l'Objet | The ID of the Object.
Name.s ; Le nom de l'Objet. | The Name of the Object.
X.i ; La coordonnée ou valeur X. | The X coordinate or value.
Y.i ; La coordonnée ou valeur Y. | The Y coordinate or value.
EndStructure
; ======================================================
; Interface pour les méthodes de l'Objet.
; Interface for Object methods.
; ======================================================
Interface ObjectMethods ; Les Noms des procédures doivent être identiques à ceux du code, avec les mêmes types et les mêmes paramètres.
; The names of the procedures must be identical to those in the code, with the same types and the same parameters.
Abc123.i()
Abc246.i()
AbcXY.i()
AbcStr.s()
AbcBox.s(Title.s, Message.s)
DeleteObject.b()
GetProperties.i()
EndInterface
; ======================================================
; Structure principale de l'Objet.
; Main Object structure.
; ======================================================
Structure StructureObject
*VirtualTableObject ; Pointeur (*VirtualTableObject) sans type, qui pointe vers l'adresse des procedures. | Pointer (*VirtualTableObject) without type, which points to the address of the procedures.
Properties.ObjectProperties ; (*Properties) de type ObjectProperties qui pointe vers les propriétés (état). | Pointer (*Properties) of type ObjectProperties that points to properties (state).
EndStructure
; Make the Methodes public to call it directly
; For Interface call it can be private
Declare.i Abc123(*Object.StructureObject)
Declare.i Abc246(*Object.StructureObject)
Declare.i AbcXY(*Object.StructureObject)
Declare.s AbcStr(*Object.StructureObject)
Declare.s AbcBox(*Object.StructureObject, Title.s, Message.s)
Declare.b DeleteObject(*Object.StructureObject)
Declare.i NewObject()
Declare.i GetProperties(*Object.StructureObject)
EndDeclareModule
Module MyObj
Global NextObjectID.i = 1
; ======================================================
; Des procédures quelconque.
; Any procedures.
; ======================================================
Procedure.i Abc123(*Object.StructureObject)
ProcedureReturn 123 ; Retourne la valeur entière 123. | Returns the integer value 123.
EndProcedure
Procedure.i Abc246(*Object.StructureObject)
ProcedureReturn 246 ; Retourne la valeur entière 246. | Returns the integer value 246.
EndProcedure
Procedure.i AbcXY(*Object.StructureObject)
; Si l'Objet est valide. | If the Object is valid.
If *Object
ProcedureReturn *Object\Properties\X + *Object\Properties\Y
Else
Debug "Error: Object Or properties Not initialized."
ProcedureReturn 0
EndIf
EndProcedure
Procedure.s AbcStr(*Object.StructureObject)
; Si l'Objet est valide. | If the Object is valid.
If *Object
ProcedureReturn "X + Y = " + Str(*Object\Properties\X + *Object\Properties\Y)
Else
Debug "Error: Object Or properties Not initialized."
ProcedureReturn ""
EndIf
EndProcedure
Procedure.s AbcBox(*Object.StructureObject, Title.s, Message.s)
; Affiche une boîte de message avec un titre et un message, puis retourne une chaîne de confirmation.
; Displays a message box with a title and message, then returns a confirmation string.
MessageRequester(Title, Message)
ProcedureReturn "Message displayed !"
EndProcedure
; ======================================================
; Détruit un objet et libère toute sa mémoire allouée.
; Destroys an Object and releases all its allocated memory.
; ======================================================
Procedure.b DeleteObject(*Object.StructureObject)
; Vérifie si l'objet est valide (non-nul) | Checks if Object is valid (non-null).
If *Object
; If *Object\Properties
; FreeStructure(*Object\Properties) ; Libère les propriétés | Frees properties.
; EndIf
;
; If *Object\Methods
; FreeStructure(*Object\Methods) ; Libère les méthodes | Frees methods.
; EndIf
FreeStructure(*Object) ; Libère l'objet principal | Frees main Object.
ProcedureReturn 1
Else
Debug "Error: Object Not initialized: " + Str(*Object)
ProcedureReturn 0
EndIf
EndProcedure
Procedure,i GetProperties(*Object.StructureObject)
ProcedureReturn @*Object\Properties
EndProcedure
; ======================================================
; Création d'un nouvel Objet.
; Creating a new Object.
; ======================================================
Procedure.i NewObject()
; Déclare un Pointeur (*Object) protégé de type StructureObject, qui prend comme valeur l'adresse de la structure "StructureObject".
; Ensuite, alloue un nouvel Objet de type Structure dynamique.
;
; Declares a protected Pointer (*Object) of type StructureObject, which takes as a value the address of the "StructureObject" structure.
; Then, allocates a new Object of dynamic Structure type.
Protected *Object.StructureObject = AllocateStructure(StructureObject)
; Si l'Objet *Object est bien initialisé.
; If the Object *Object is properly initialized.
If *Object.StructureObject
*Object\VirtualTableObject = ?VirtualTableObject
; ; Alloue un nouvel Objet "Properties" de type Structure dynamique qui prend comme valeur l'adresse de la structure "ObjectProperties".
; ; Allocates a new "Properties" Object of dynamic Structure type which takes as a value the address of the "ObjectProperties" structure.
; *Object\Properties = AllocateStructure(ObjectProperties)
;
; ; Si l'Objet "Properties" n'est pas initialisé.
; ; If the "Properties" Object is not initialized.
; If Not *Object\Properties
; Debug "Error: Unable To allocate Object properties."
; FreeStructure(*Object) ; Supprime l'Objet car il a pu être créé. | Remove the Object as it has been created.
; ProcedureReturn 0
; EndIf
; Affecte un Numéro d'identification à l'Objets en fonction de la variable NextObjectID.i.
; Assigns an identification number to the object according to the NextObjectID.i variable.
*Object\Properties\ID = NextObjectID
NextObjectID.i + 1
; Alloue un nouvel Objet "Methods" de type Structure dynamique qui prend comme valeur l'adresse de la structure "ObjectMethods".
; Allocates a new "Methods" Object of dynamic Structure type which takes as a value the address of the "ObjectMethods" structure.
; *Object\Methods = AllocateStructure(ObjectMethods)
; Si l'Objet "Methods" n'est pas initialisé.
; If the "Methods" Object is not initialized.
; If Not *Object\Methods
; Debug "Error: Unable To allocate Object methods."
; FreeStructure(*Object\Properties) ; Supprime les propriétés de l'Objet car elles ont pu être créées. | Remove the properties of the Object as they have been created.
; FreeStructure(*Object) ; Supprime l'Objet car il a pu être créé. | Remove the Object as it has been created.
; ProcedureReturn 0
; EndIf
; Methods reçois la structure de l'Objet ou la Table Virtuel est stocké pour réfférencer les Procédures.
; Methods receives the structure of the Object where the Virtual Table is stored to refferentiate the Procedures.
; *Object\Methods = *Object ; Error Here !
; Retourne un pointeur qui est l'adresse mémoire de la structure "StructureObject".
; Returns a pointer which is the memory address of the "StructureObject" structure.
ProcedureReturn *Object
Else
ProcedureReturn 0
EndIf
EndProcedure
; Création de la table virtuel, elle sert à stocker les adresses des procédures (Médhodes).
; Create virtual table, It is used to store procedure addresses (Medhodes).
DataSection
VirtualTableObject:
Data.i @Abc123()
Data.i @Abc246()
Data.i @AbcXY()
Data.i @AbcStr()
Data.i @AbcBox()
Data.i @DeleteObject()
Data.i @GetProperties()
EndDataSection
EndModule
; --------------------------------
; Exemple d'utilisation:
; Example of use:
; ======================================================
; Création d'instance.
; Instance creation.
; ======================================================
UseModule MyObj
; ***************************************************
; This example is with direct call into Modul - not using the interface
; ***************************************************
*MyObject.StructureObject = NewObject() ; Crée un nouvel Objet. | Creates a new Object.
; Si l'Objet existe. | If the Object exists.
If *MyObject
Debug "Adress Object: " + Str(*MyObject) ; Affiche l'adresse mémoire de l'instance de l'Objet. | Displays the memory address of the Object instance.
Debug "Adress Object Properties: " + Str(*MyObject\Properties) ; Affiche l'adresse mémoire de la structure des propriétés. | Displays the memory address of the properties structure.
;Debug "Adress Object Methods: " + Str(*MyObject\Methods) ; Affiche l'adresse mémoire de la structure des méthodes. | Displays the memory address of the methods structure.
Debug "-----------------------------------"
; ======================================================
; Modification des propriétés.
; Modification of properties.
; ======================================================
*MyObject\Properties\Name = "Object #1" ; Définit la propriété Name à "Object #1". | Sets Name property to "Object #1".
*MyObject\Properties\X = 15 ; Définit la propriété X à la valeur de 15. | Sets X property to 15.
*MyObject\Properties\Y = 25 ; Définit la propriété Y à la valeur de 25. | Sets Y property to 25.
Debug "Object ID: " + Str(*MyObject\Properties\ID) ; Affiche la valeur de la propriété ID. | Displays ID property value.
Debug "Object X: " + Str(*MyObject\Properties\X) ; Affiche la valeur de la propriété X. | Displays X property value.
Debug "Object Y: " + Str(*MyObject\Properties\Y) ; Affiche la valeur de la propriété Y. | Displays Y property value.
Debug "Object Name: " + *MyObject\Properties\Name ; Affiche la valeur de la propriété Name sous forme de chaîne. | Displays Name property value as a string.
Debug "-----------------------------------"
Debug "Object Fonction Abc123: " + Str(Abc123(*MyObject)) ; Appelle et affiche le résultat de la méthode Abc123(). | Calls and displays result from Abc123 method().
Debug "Object Fonction Abc246: " + Str(Abc246(*MyObject)) ; Appelle et affiche le résultat de la méthode Abc246(). | Calls and displays result from Abc246 method().
Debug "Object Fonction AbcXY: " + Str(AbcXY(*MyObject)) ; Appelle et affiche le résultat de la méthode AbcXY(). | Calls and displays result from AbcXY method().
Debug "Object Fonction AbcStr: " + AbcStr(*MyObject) ; Appelle et affiche le résultat de la méthode AbcStr(). | Calls and displays result from AbcStr method().
; Appel de la méthode avec paramètres: - Calling a method with parameters:
Debug "Result of AbcBox: " + AbcBox(*MyObject,"Information", "Hello, world!")
DeleteObject(*MyObject) ; Non référencer mais est accepté ! - ; Not referenced but is accepted!
Else
Debug "Erreur: Objet non initialisés: " + Str(*MyObject)
EndIf
Debug ""
Debug "With Interface"
Debug ""
; ***************************************************
; This example is with using the Obj.-Interface
; ***************************************************
*MyObj.ObjectMethods = NewObject() ; Crée un nouvel Objet. | Creates a new Object.
; Si l'Objet existe. | If the Object exists.
If *MyObject
Debug "Adress Object: " + Str(*MyObj) ; Affiche l'adresse mémoire de l'instance de l'Objet. | Displays the memory address of the Object instance.
Debug "Adress Object Properties: " + Str(*MyObj\GetProperties()) ; Affiche l'adresse mémoire de la structure des propriétés. | Displays the memory address of the properties structure.
;Debug "Adress Object Methods: " + Str(*MyObject\Methods) ; Affiche l'adresse mémoire de la structure des méthodes. | Displays the memory address of the methods structure.
Debug "-----------------------------------"
; ======================================================
; Modification des propriétés.
; Modification of properties.
; ======================================================
*ObjProp.ObjectProperties = *MyObj\GetProperties()
*ObjProp\Name = "Object #1" ; Définit la propriété Name à "Object #1". | Sets Name property to "Object #1".
*ObjProp\X = 15 ; Définit la propriété X à la valeur de 15. | Sets X property to 15.
*ObjProp\Y = 25 ; Définit la propriété Y à la valeur de 25. | Sets Y property to 25.
Debug "Object ID: " + Str(*ObjProp\ID) ; Affiche la valeur de la propriété ID. | Displays ID property value.
Debug "Object X: " + Str(*ObjProp\X) ; Affiche la valeur de la propriété X. | Displays X property value.
Debug "Object Y: " + Str(*ObjProp\Y) ; Affiche la valeur de la propriété Y. | Displays Y property value.
Debug "Object Name: " + *ObjProp\Name ; Affiche la valeur de la propriété Name sous forme de chaîne. | Displays Name property value as a string.
Debug "-----------------------------------"
Debug "Object Fonction Abc123: " + Str(*MyObj\Abc123()) ; Appelle et affiche le résultat de la méthode Abc123(). | Calls and displays result from Abc123 method().
Debug "Object Fonction Abc246: " + Str(*MyObj\Abc246()) ; Appelle et affiche le résultat de la méthode Abc246(). | Calls and displays result from Abc246 method().
Debug "Object Fonction AbcXY: " + Str(*MyObj\AbcXY()) ; Appelle et affiche le résultat de la méthode AbcXY(). | Calls and displays result from AbcXY method().
Debug "Object Fonction AbcStr: " + *MyObj\AbcStr() ; Appelle et affiche le résultat de la méthode AbcStr(). | Calls and displays result from AbcStr method().
; Appel de la méthode avec paramètres: - Calling a method with parameters:
Debug "Result of AbcBox: " + *MyObj\AbcBox("Information", "Hello, world!")
DeleteObject(*MyObj) ; Non référencer mais est accepté ! - ; Not referenced but is accepted!
Else
Debug "Erreur: Objet non initialisés: " + Str(*MyObject)
EndIf