PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WEBDEV 2024 → Access to PRIVATE members from any other classes
Access to PRIVATE members from any other classes
Débuté par Luis García, 21 aoû. 2017 18:20 - 3 réponses
Membre enregistré
11 messages
Posté le 21 août 2017 - 18:20
My colleague built a webapp using global/public variables. For example, he wrote a class named xUsuario. Later, he used an xUsuario object, called oUsuario as a property of another class (tApplication). To change any of the properties values of the oUsuario object, he just had to do what’s in the green rectangle below:






Now I would like to rewrite the app, without having to use global/public variables, and using getters and setters. For example, xUsuario would become xUsuarioNew, with the following structure:






Then, I create a tApplicationNew class, using an xUsuarioNew as one of its properties:





And now the question: how can I assign new values to the oUsuario object from any other classes? Obviously, since the members are now private, this won’t be valid anymore (please note that oAppNew is a tApplicationNew object):






I’ve tried using the following syntax, which raises an error:






As you have probably noticed, I am totally new to Webdeb. Any help will be welcome.

Thank you very much.
Message modifié, 21 août 2017 - 18:21
Membre enregistré
794 messages
Popularité : +40 (42 votes)
Posté le 22 août 2017 - 21:16
Hi. You can write in the class a procedure to change the value of your PRIVATE members variables.


Rubén
Membre enregistré
11 messages
Posté le 23 août 2017 - 09:32
Hi Rubén, thanks for your response.

I found the solution you're suggesting on the PCSoft documentation before you answered, and I tried it in a separate (smaller) project for testing purposes. It worked. However, when applying it to this project, I'm still getting the "Object not allocated" error.

This is what I've done. In the tApplicationNew class I wrote a procedure for each one of the private variables. For example:

// Retrieving the cSetGetApplicationUsuarioId property
Procedure PUBLIC nSetGetApplicationUsuarioId() : int
RESULT oUsuario.nId

// Assigning the cSetGetApplicationUsuarioId property
Procedure PUBLIC nSetGetApplicationUsuarioId(Value is int)
oUsuario.nId=Value


And in the XLogin class, where I intend to modify those variables, I wrote the following:

oAppNew.nSetGetApplicationUsuarioId = Val(cId)
oAppNew.cSetGetApplicationUsuarioCod = cId
oAppNew.cSetGetApplicationUsuarioNom = cUser
oAppNew.cSetGetApplicationUsuarioPerm = cPerm
oAppNew.cSetGetApplicationUsuarioCodZona = oRecUser.aResultado[1].cCodZona
oAppNew.cSetGetApplicationUsuarioCodArea = oRecUser.aResultado[1].cCodArea
oAppNew.cSetGetApplicationUsuarioCodDis = oRecUser.aResultado[1].cCodDis
oAppNew.cSetGetApplicationUsuarioCodRuta = oRecUser.aResultado[1].cCodRuta


This worked in my testing project, but not in this one:





The error refers to the procedure, which by the way was generated with the Webdev wizard an it only contains a single line. I'm a bit confused.

Again, thanks for your response. If I ever found how to solve this, I'll post here.
Membre enregistré
11 messages
Posté le 31 août 2017 - 13:46
Hi, I found the solution. I simply had to create a global object and its corresponding 'SetGet' procedures wherever I needed to retrieve a value.