PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Description de variable
Description de variable
Débuté par Charly CANDO, 15 aoû. 2017 17:30 - 5 réponses
Membre enregistré
948 messages
Popularité : +30 (92 votes)
Posté le 15 août 2017 - 17:30
Coucou,

// Récupère la définition de la classe ou de la structure type de la variable x
MaDéfinition est une Definition
MaDéfinition = RécupèreDéfinition(x)
// Récupère la description du membre nValeur de la classe ou de la structure
m est une Description de Variable
m = MaDéfinition..Variable["nValeur"]


Ok parfait ...

Maintenant je voudrais savoir si la variable

1)Est "mapping" et connaitre le nom du mapping.
2)Est "Serialize"
3)Est "clé unique"

Bref, connaitre les description complementaire sur sa définition, du genre

m_sID est un entier sur 8 octets <mapping=ID, Serialize = Faux, clé unique>


Des iddées ?

Mici

--
Charly CanDo.
Forg en Nouvelle-Zélande ;-) - In üs we trust
Nasi Goreng en Indonesie ;-) - #oulouou
Char Kuey Tiao en Malaisie ;-) - #OKLM
Ratatouille en Provence ;-)
irc.freenode.net - ##pcsoft
Membre enregistré
3 845 messages
Popularité : +227 (347 votes)
Posté le 16 août 2017 - 07:38
Les variable de type définitions me posent aussi des problèmes depuis quelque jours.

La réponse dépend du type de ta variable.
-Si elle est globale la réponse est oui, l'ID sera alors récupérée via m..Nom (dans ton cas x) clé unique
-Si elle est locale, elle ne sera unique que dans sa portée

Si ta variable est complexe, cela se complique dans la mesure où il faut jouer avec la récursivité pour avoir l'unicité.

Prenons le cas suivant
STMembreStruct est une structure
sMembre1 est une chaîne
nMembre2 est un entier
sMembre3 est chaîne
FIN

STTestStruct est une structure
sMembre3 est une chaîne
stMembre4 est STMembreStruct
FIN


x est STTestStruct
y est STTestStruct


On voit très bien que sMembre3 n'est pas unique. Par contre x.sMembre3 peut être unique dans les conditions citées en début de post.

En ce qui concerne la sérialisation, je n'ai pas testé.

--
Il y a peut être plus simple, mais, ça tourne
Membre enregistré
3 845 messages
Popularité : +227 (347 votes)
Posté le 16 août 2017 - 16:55
Comme je l'expliquais ce matin, je suis en train de me pencher sur le type définition.
Voici un petit code qui, je l'espère, pourra t'aider à comprendre la manière dont est structuré ce type de variable.
J'ai volontairement laissé les "Trace"
// Résumé : Récupère le nom des membres d'une variable composite dans un tableau
// Description des paramètres d'entrée/sortie de 'DécomposeVariable' :
//
// Syntaxe :
//DécomposeVariable (<DefObjet> est Définition, <tabDefMembre> est tableau [, <nCompteur> est entier [, <sMembrePère> est chaîne]])
//
// Paramètres :
// DefObjet (Définition) : Définition de la variable composite à décomposer
// tabDefMembre (tableau) : Nom du tableau résultat. Lors du premier appel, il s'agit d'un tableau dynamique de 1 chaîne
// nCompteur (entier - valeur par défaut=0) : Emplacement du membre dans le tableau
// sMembrePère (chaîne ANSI - valeur par défaut="") : Nom du membre composite auquel se rapporte le membre en cours
// Valeur de retour :
// Aucune
//
// Limites :
// Cette procédure à n'a pas été testée pour une profondeur de composition >1 (i.e. elle est pour l'instant limitée à une variable
// composite avec des membres composites dont les membres sont des variables simples.)
// Cette procédure n'a pas été testée pour des objets prédéfinis de WINDEV

Procedure PRIVÉE DécomposeVariable(DefObjet est un Definition,tabDefMembre est tableau dynamique,nCompteur est entier=0,sMembrePère est chaîne="")
DefSousObjet est Definition
VarObjet est Description de Variable

//A FAIRE: Tester avec une profondeur > 1 et éventuellement voir pour l'utilisation d'une pile
POUR TOUT VarObjet de DefObjet..Variable
Trace("Appel de la procédure pour une variable de type: "+DefObjet..Nom)
nCompteur++
Dimension(tabDefMembre,nCompteur)
SI sMembrePère="" ALORS
tabDefMembre[nCompteur]=VarObjet..Nom
SINON
tabDefMembre[nCompteur]=sMembrePère+"."+VarObjet..Nom
FIN

SELON Val(VarObjet..Définition..Type)
CAS 35,36,37 //Variable composée, Classe ou Structure, on va être obligé de décomposer
nCompteur-- //On va récupérer le nom du premier membre de la variable composite à la place actuelle
Trace("Appel récursif pour le membre "+VarObjet..Nom+" dont la définition est "+VarObjet..Définition)
DefSousObjet=VarObjet..Définition
DécomposeVariable(DefSousObjet,tabDefMembre,nCompteur,VarObjet..Nom)
Trace("On en a fini pour le membre composite"+VarObjet..Définition)
AUTRE CAS
FIN
FIN


--
Il y a peut être plus simple, mais, ça tourne
Membre enregistré
948 messages
Popularité : +30 (92 votes)
Posté le 18 août 2017 - 00:07
Coucou,

Dandypunk je te remercie pour ta réponse ... et j'ai particuliére aprécier que tu prennes le temps de m'aider :D

Donc en vrais, au moment ou j'ai posé la question j'imaginais bien que aucune solutions n'existes, a ma connaisance, on ne peut pas
savoir :
1) Le mapping d'une variable
2) Si la variable est sérializable
3) Si la variable est clef unique.

Ce sont des informations qui m'interesse beaucoup et j espere les avoirs de disponible dans la version 23.

Mais crois moi, j'ai était toucher par ta réponse, alors je t'ai ecris un code spécialement pour toi, j'espere que il te seras utiles, et si tu as n'importe quel question sur ce code je serais vraimment ravis de t'aider.

Dandypunk :

CTools_Enumerating est une Classe
PRIVÉE
// Object to enumerate
m_pclObject est un object dynamique
// http://doc.pcsoft.fr/fr-FR/?1000019560
m_xDefinition est une Definition
// Definitions
m_taDefinitions est un tableau associatif de tableau associatif de Variant
FIN


Procedure Constructeur(_pclObject est un object dynamique)
// Object
:m_pclObject <- _pclObject


Procedure Destructeur()


Procedure PRIVÉE Definition() : Definition
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Retrieves the definition of the element type.
SI :m_xDefinition..Nom ~= "" ALORS
:m_xDefinition = RécupèreDéfinition(:m_pclObject)
FIN
// Summary
RENVOYER :m_xDefinition
CAS ERREUR:
ErreurPropage()
RENVOYER Null
CAS EXCEPTION:
ExceptionPropage()
RENVOYER Null


Procedure PUBLIQUE Definition(_xDefinition est Definition)
:m_xDefinition = _xDefinition


Procedure PUBLIC Definitions()
RENVOYER :m_taDefinitions


Procedure PRIVÉE Definitions(_taDefinitions)
:m_taDefinitions = _taDefinitions


Procedure PRIVÉE GetDefinition(_xDefinition est une Definition)<multisyntaxe>: tableau associatif de tableau associatif de Variant
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Definitions
_taDefinitions est un tableau associatif de tableau associatif de Variant
// Contents
_taContents est un tableau associatif de Variant

// Procedure
POUR TOUT _Procedure de _xDefinition..Procédure
_taContents[_Procedure..Nom] = :GetDefinitionProcedure(_Procedure)
FIN
SI TableauOccurrence(_taContents) > 0 ALORS
_taDefinitions["Procedures"] = _taContents
FIN

// Variables
VariableRAZ(_taContents)
POUR TOUT _Variable de _xDefinition..Variable
_taContents[_Variable..Nom] = :GetDefinitionVariable(_Variable)
FIN
SI TableauOccurrence(_taContents) > 0 ALORS
_taDefinitions["Variables"] = _taContents
FIN

// Propertys
VariableRAZ(_taContents)
POUR TOUT _Property de _xDefinition..Propriété
_taContents[_Property..Nom] = :GetDefinitionProperty(_Property)
FIN
SI TableauOccurrence(_taContents) > 0 ALORS
_taDefinitions["Propertys"] = _taContents
FIN

// Summary
RENVOYER _taDefinitions
CAS ERREUR:
VariableRAZ(_taDefinitions)
ErreurPropage()
RENVOYER _taDefinitions
CAS EXCEPTION:
VariableRAZ(_taDefinitions)
ExceptionPropage()
RENVOYER _taDefinitions


Procedure PRIVÉE GetDefinitionProcedure(_xDescription est une Description de Procedure): tableau associatif de Variant
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Procedures
_taProcedure est un tableau associatif de Variant
AVEC _xDescription
// Procedures
_taProcedure["Nom"] = ..Nom
_taProcedure["Global"] = ..Global
_taProcedure["Hérité"] = ..Hérité
_taProcedure["Virtual"] = ..Virtual
FIN
// Summary
RENVOYER _taProcedure
CAS ERREUR:
VariableRAZ(_taProcedure)
ErreurPropage()
RENVOYER _taProcedure
CAS EXCEPTION:
VariableRAZ(_taProcedure)
ExceptionPropage()
RENVOYER _taProcedure


Procedure PRIVÉE GetDefinitionProperty(_xDescription est une Description de Propriété): tableau associatif de Variant
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Propertys
_taProperty est un tableau associatif de Variant
AVEC _xDescription
// Propertys
_taProperty["Nom"] = ..Nom
_taProperty["Global"] = ..Global
_taProperty["Hérité"] = ..Hérité
_taProperty["Virtual"] = ..Virtual
_taProperty["Lecture"] = ..Lecture
_taProperty["Ecriture"] = ..Ecriture
FIN
// Summary
RENVOYER _taProperty
CAS ERREUR:
VariableRAZ(_taProperty)
ErreurPropage()
RENVOYER _taProperty
CAS EXCEPTION:
VariableRAZ(_taProperty)
ExceptionPropage()
RENVOYER _taProperty


Procedure PRIVÉE GetDefinitionVariable(_xDescription est une Description de Variable): tableau associatif de Variant
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Variable
_taVariable est un tableau associatif de Variant
AVEC _xDescription
// Variables
_taVariable["Nom"] = ..Nom
_taVariable["Global"] = ..Global
_taVariable["Hérité"] = ..Hérité
_taVariable["Masquage"] = ..Masquage
_taVariable["Type"] = CTools_Enumerating::GetTypeVarName(..Définition..Type)
// Nouveauté 22
// http://doc.pcsoft.fr/fr-FR/?1000019560
SI Val(Gauche(VersionWinDev(versionVM), 2)) > 21
_taVariable["Associé"] = ..Associé
FIN
// Nouveauté 23 !
// Connaitre les description complementaire sur la définition de la variable de classe
// => m_sID est un entier sur 8 octets <mapping=ID, Serialize = Faux, clé unique>
// Etc .....
SI Val(Gauche(VersionWinDev(versionVM), 2)) > 22
_taVariable["Mapping"] = ..Mapping
_taVariable["CléUnique"] = ..CléUnique
_taVariable["Serialize"] = ..Serialize
FIN
FIN
// Definitions
_taContents est un tableau associatif de tableau associatif de Variant
SELON _xDescription..Définition..Type
// Tableau
CAS wlTableau, ...
wlTableauAssociatif
// Definitions
_taDefinitions est un tableau associatif de tableau associatif de Variant
// Definition variables
_taDefinitionVariables est un tableau associatif de tableau associatif de tableau associatif de Variant
AVEC _xDescription..Déclaration
POUR _nIndice = 1 _TO_ ..Variable..Occurrence
SELON ..Type
CAS wlTableau, ...
wlTableauAssociatif, ...
wlInstance, ...
wlStructure
// Composé
_taDefinitionVariables[..Variable[_nIndice]..Nom] <- CTools_Enumerating:GetDefinition(_xDescription..Définition)
AUTRE CAS
// Primitif
_taDefinitions[..Variable[_nIndice]..Nom] = CTools_Enumerating:GetDefinitionVariable(..Variable[_nIndice])
FIN
FIN
FIN
// $:-]
SELON Vrai
CAS TableauOccurrence(_taDefinitions) > 0
_taContents <- _taDefinitions
CAS TableauOccurrence(_taDefinitionVariables) > 0
_taVariable["Contents"] <- _taDefinitionVariables
FIN
// Composé
CAS wlInstance, ...
wlStructure
_taContents <- :GetDefinition(_xDescription..Définition)
FIN
SI TableauOccurrence(_taContents) > 0 ALORS
_taVariable["Contents"] <- _taContents


// Expression : _taContents => Ok





// : _taVariable["Contents"] => _taVariable["Contents"]["Variables"] => Ok





// Clic sur + => _taVariable["Contents"]["Variables"]["Variables"] => ??





// : _taVariable["Contents"]["Variables"] - place des espaces deriere le ] c marrant aussi ^^





// #QuestSide
// https://www.youtube.com/watch?v=cDnPNacRzdA
// : _taVariable["Contents"]["Variables"]["sMembre1"] => #Héhé :-)





// #01F210067F
FIN
// Summary
RENVOYER _taVariable
CAS ERREUR:
VariableRAZ(_taVariable)
ErreurPropage()
RENVOYER _taVariable
CAS EXCEPTION:
VariableRAZ(_taVariable)
ExceptionPropage()
RENVOYER _taVariable


Procedure PUBLIC GetDefinitions()
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Definitions
:m_taDefinitions <- :GetDefinition(:Definition)
// Summary
RENVOYER :Definitions
CAS ERREUR:
VariableRAZ(:m_taDefinitions)
ErreurPropage()
RENVOYER :Definitions
CAS EXCEPTION:
VariableRAZ(:m_taDefinitions)
ExceptionPropage()
RENVOYER :Definitions


Procedure PUBLIC GLOBAL GetTypeVarName(_nTypeVar est un entier): chaîne
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Nom du type
_sTypeVarName est une chaîne
// Identifie le nom du type d'une expression, d'une variable (lors d'un appel de procédure par exemple) ou d'un champ.
SELON _nTypeVar
CAS 0
_sTypeVarName = "Champs qui ne renvoient pas de valeur (bouton, champ OLE, ...)."
CAS wlBooléen
_sTypeVarName = "wlBooléen"
CAS wlEntierSansSigne_1
_sTypeVarName = "wlEntierSansSigne_1"
CAS wlEntierSansSigne_2
_sTypeVarName = "wlEntierSansSigne_2"
CAS wlEntierSansSigne_4
_sTypeVarName = "wlEntierSansSigne_4"
CAS wlEntierSansSigne_8
_sTypeVarName = "wlEntierSansSigne_8"
CAS wlEntier_1
_sTypeVarName = "wlEntier_1"
CAS wlEntier_2
_sTypeVarName = "wlEntier_2"
CAS wlEntier
_sTypeVarName = "wlEntier"
CAS wlEntier_8
_sTypeVarName = "wlEntier_8"
CAS wlMonétaire
_sTypeVarName = "wlMonétaire"
CAS wlRéel_4
_sTypeVarName = "wlRéel_4"
CAS wlRéel
_sTypeVarName = "wlRéel"
CAS wlHandle
_sTypeVarName = "wlHandle"
CAS wlCaractère
_sTypeVarName = "wlCaractère"
// cas wlChaîne
// Attention : la constante wlChaîne peut correspondre à une chaîne de caractères Ansi ou Unicode selon la configuration du projet :•
// Dans un projet compatible 16, cette constante vaut 19,
// Dans un projet Unicode, cette constante vaut 16.
CAS wlChaîneAnsi
_sTypeVarName = "wlChaîneAnsi"
CAS wlChaîneUnicode
_sTypeVarName = "wlChaîneUnicode"
CAS wlSourceDeDonnées
_sTypeVarName = "wlSourceDeDonnées"
CAS wlChaînePascal
_sTypeVarName = "wlChaînePascal"
CAS wlChaîneFixe
_sTypeVarName = "wlChaîneFixe"
CAS wlChaîneASCIIZ
_sTypeVarName = "wlChaîneASCIIZ"
CAS wlDate
_sTypeVarName = "wlDate"
CAS wlHeure
_sTypeVarName = "wlHeure"
CAS wlDateHeure
_sTypeVarName = "wlDateHeure"
CAS wlDurée
_sTypeVarName = "wlDurée"
CAS wlBuffer
_sTypeVarName = "wlBuffer"
CAS wlMémoBinaire
_sTypeVarName = "wlMémoBinaire"
CAS wlVariant
_sTypeVarName = "wlVariant"
CAS wlAutomation
_sTypeVarName = "wlAutomation"
CAS wlChampOLE
_sTypeVarName = "wlAutomation"
CAS wlTableau
_sTypeVarName = "wlTableau"
CAS wlTableauAssociatif
_sTypeVarName = "wlTableauAssociatif"
CAS wlVariableComposée
_sTypeVarName = "wlVariableComposée"
CAS wlStructure
_sTypeVarName = "wlStructure"
CAS wlInstance
_sTypeVarName = "wlInstance"
CAS wlDescriptionFichier
_sTypeVarName = "wlDescriptionFichier"
CAS wlDescriptionRubrique
_sTypeVarName = "wlDescriptionRubrique"
CAS wlDescriptionLiaison
_sTypeVarName = "wlDescriptionLiaison"
CAS wlPolice
_sTypeVarName = "wlPolice"
CAS wlNumérique
_sTypeVarName = "wlNumérique"
CAS wlConnexion
_sTypeVarName = "wlConnexion"
CAS wlObjetDotNet
_sTypeVarName = "wlObjetDotNet"
CAS wlEnumeration
_sTypeVarName = "wlEnumération"
CAS wlCombinaison
_sTypeVarName = "wlCombinaison"
CAS wlChamp
_sTypeVarName = "wlChamp"
AUTRE CAS
_sTypeVarName = "Unknown"
dbgErreur(ChaîneConstruit("TypeVar: '%1' Unknown !", _nTypeVar))
FIN
// Summary
RENVOYER _sTypeVarName
CAS ERREUR:
ErreurPropage()
RENVOYER ""
CAS EXCEPTION:
ExceptionPropage()
RENVOYER ""


Procedure PUBLIC Trace(): boolean
// Gestion des erreurs
ErreurChangeParamètre(epGotoCasErreur)
ExceptionChangeParamètre(epGotoCasException)
// Ouvre la fenêtre de trace
TraceDébut(trCreation+trDessusTout) // + trFichier

_TraceTableauAssociatif(:Definitions)
// Trace les Definitions
PROCEDURE INTERNE _TraceTableauAssociatif(_taTableau, _nDepth est un entier = 0)
POUR TOUT _xElement, _sKey de _taTableau
QUAND EXCEPTIONEXCEPTION DANS
TraceConstruit("%1>%2" + TAB + "%3", Répète(" ", _nDepth), _sKey, _xElement)
FAIRE
ExceptionActive()
TraceConstruit("%1+%2", Répète(" ", _nDepth), _sKey)
// Recursif ^^
_TraceTableauAssociatif(_xElement, _nDepth + 1)
FIN
FIN
FIN
// Summary
RENVOYER Vrai
CAS ERREUR:
ErreurInfo(errMessage)
RENVOYER Faux
CAS EXCEPTION:
ExceptionInfo(errMessage)
RENVOYER Faux


=====================
STMembreStruct est une structure
sMembre1 est une chaîne
nMembre2 est un entier
sMembre3 est chaîne
FIN

STTestStruct est une structure
sMembre3 est une chaîne
stMembre4 est STMembreStruct
FIN

CTools_Test est une Classe
x est STTestStruct
y est STTestStruct
FIN

Procedure Constructeur()
Procedure Destructeur()


_clCTools_Test est un CTools_Test

_clCTools_Enumerating est un CTools_Enumerating(_clCTools_Test)
AVEC _clCTools_Enumerating
.GetDefinitions()
.Trace()
FIN


Le fichier de trace de l'example que tu as fournis
+Variables
 +x
  >Nom x
  >Global 0
  >Hérité 0
  >Masquage 0
  >Type wlStructure
  +Contents
   +Variables
    +sMembre3
     >Nom sMembre3
     >Global 0
     >Hérité 0
     >Masquage 0
     >Type wlChaîneAnsi
    +stMembre4
     >Nom stMembre4
     >Global 0
     >Hérité 0
     >Masquage 0
     >Type wlStructure
     +Contents
      +Variables
       +sMembre1
        >Nom sMembre1
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlChaîneAnsi
       +nMembre2
        >Nom nMembre2
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlEntier
       +sMembre3
        >Nom sMembre3
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlChaîneAnsi
 +y
  >Nom y
  >Global 0
  >Hérité 0
  >Masquage 0
  >Type wlStructure
  +Contents
   +Variables
    +sMembre3
     >Nom sMembre3
     >Global 0
     >Hérité 0
     >Masquage 0
     >Type wlChaîneAnsi
    +stMembre4
     >Nom stMembre4
     >Global 0
     >Hérité 0
     >Masquage 0
     >Type wlStructure
     +Contents
      +Variables
       +sMembre1
        >Nom sMembre1
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlChaîneAnsi
       +nMembre2
        >Nom nMembre2
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlEntier
       +sMembre3
        >Nom sMembre3
        >Global 0
        >Hérité 0
        >Masquage 0
        >Type wlChaîneAnsi


Merci encore a toi Dandypunk $-]

--
Charly CanDo.
Forg en Nouvelle-Zélande ;-) - In üs we trust
Nasi Goreng en Indonesie ;-) - #oulouou
Char Kuey Tiao en Malaisie ;-) - #OKLM
Ratatouille en Provence ;-)
irc.freenode.net - ##pcsoft
Message modifié, 18 août 2017 - 01:44
Membre enregistré
948 messages
Popularité : +30 (92 votes)
Posté le 23 janvier 2018 - 21:31
Up !

--
In üs we trust.
Autopsie Volume 1 disponible au dépot de ton armurier: http://www.sitealademande.com/sitealamande/anywhere/depot
Posté le 09 septembre 2021 - 09:51
Malheureusement il n'existe rien (à ma connaissance) pour ce faire.

Je rêve pourtant également d'avoir un moyen de récupérer le mapping et le nom sérialisé d'un membre de classe.

Par exemple des propriétés directes comme :MonMembre..Mapping et :MonMembre..Serialise

En attendant, pour rendre mon code générique, je suis obligé de déclarer des tableaux de structures qui contiennent toutes ces informations, c'est redondant et il est très facile de faire des erreurs ou oublier.