|
FORUMS PROFESSIONNELS WINDEV, WEBDEV et WINDEV Mobile |
| | | | | |
WD12 How to declare a static variable? |
Débuté par Andres Sanchez, 06 jan. 2009 18:57 - 7 réponses |
| |
| | | |
|
| |
Posté le 06 janvier 2009 - 18:57 |
Hi: I don´t know how to declare a variable inside a Local Procedure that is static. the meaning of static is that it retains its value from one call to the other, as opposed to the normal dynamic one, where each time the local procedure is called it is initialized. Thanks Andres Sanchez |
| |
| |
| | | |
|
| | |
| |
Posté le 06 janvier 2009 - 19:11 |
Art: Yes in fact i was going to do just that, but then I think that there has to be a method to declare it inside the local procedure, all the other laguages I now support that. The thing is that I only need to access the variable inside the local procedure, but i need to retain its value from one call to the other. Thanks Andres Sanchez |
| |
| |
| | | |
|
| | |
| |
Posté le 06 janvier 2009 - 19:11 |
Could you declare a global and pass it in? |
| |
| |
| | | |
|
| | |
| |
Posté le 06 janvier 2009 - 23:30 |
Hi Andres, You can't : Means . this is not possible in Windev. A kind of work around is to use global variables.... This is indeed bad. What I do is to declare a class wich contains these variables as private members. You have to implement this class following the Singleton Pattern: This means you have to define the class in a way which allows you to create one and only one!! instance of the class. If you don't know yet how to implement the Singleton Pattern , just ask. .) Bjoern |
| |
| |
| | | |
|
| | |
| |
Posté le 06 janvier 2009 - 23:31 |
Hi Andres...
Directly, no
But you can create an associative Array using the full procedure name (returned by the dbgxxxx functions) as key value, and any type of field you need as value...
This way, you can have a persistent value (or values if you add a variable name in the key) for any procedure and identify it easily, while 'declaring' it only from the procedure itself
Best regards
-- Fabrice Harari International WinDev, WebDev and WinDev mobile Consulting
More information on http://www.fabriceharari.com
Andres Sanchez wrote:
Hi: I don´t know how to declare a variable inside a Local Procedure that is static. the meaning of static is that it retains its value from one call to the other, as opposed to the normal dynamic one, where each time the local procedure is called it is initialized. Thanks Andres Sanchez
|
| |
| |
| | | |
|
| | |
| |
Posté le 08 janvier 2009 - 08:14 |
yeah....humor....good Hi M.(arc?), You can also ask, why using structures ? Everything inside a structure can be defined in form of several simple declarations. I use a singleton, because it's . 1) more reliable 2) Serialisation, persistent information 3) Validation within a Setter method, just here and not spreaded around the whole app: like debugAssert(d > 0 and d |
| |
| |
| | | |
|
| | |
| |
Posté le 08 janvier 2009 - 08:14 |
Hi, Use a class with GLOBAL CONSTANT members. Here's a sample of the declaration of such a class which is instantiated in the project initialisation code making it available througout the app. The CONSTANT part is useful for your question. You can access these by using class::constantname. Of course, ideally the other members (aside of the constants) should be private or protected and managed via setters and getters.
objSession is class PUBLIC GLOBAL DIR_TEMP is string DIR_LOG is string str_IniFile is string str_ErrorLogFile is string str_SessionGUID is string str_SessionUserName is string str_SessionUserPassword is string str_SessionUserType is string int_SessionUserAffiliateID is int int_SessionUserCoworkerID is int str_SessionUserFullName is string cnx_DatabaseConnection is Connection str_DatabaseTypeHF is string str_DatabasePathHF is string str_DatabaseServerHFCS is string int_DatabasePortHFCS is int str_DatabaseNameHFCS is string str_DatabaseUserHFCS is string str_DatabasePasswordHFCS is string str_SMTPServer is string int_SMTPPort is int bool_SMTPAsynchronous is boolean str_SMTPUser is string str_SMTPPassword is string str_SMTPDefaultSender is string str_gCalendarSharedUser is string str_gCalendarSharedPassword is string str_WebmasterEmail is string bool_CCUniglobeAdmin is boolean bool_CCMCS2Admin is boolean int_DuplicateThresholdOnName is int int_DuplicateThresholdOnPostalCode is int CONSTANT CRYPTION_KEY = "SomethingBlaBla" PAGEMODE_VIEW = "View" PAGEMODE_BROWSE = "Browse" PAGEMODE_UPDATE = "Update" PAGEMODE_CREATE = "Create" USERTYPE_AFFILIATE_MANAGER = "AffiliateManager" USERTYPE_AFFILIATE_USER = "AffiliateUser" USERTYPE_ADMINISTRATOR = "Administrator" USERTYPE_CALLCENTER = "CallCenter" END PROTECTED PRIVATE END Cheers, Peter |
| |
| |
| | | |
|
| | |
| |
Posté le 08 janvier 2009 - 08:16 |
Hi Bjoern, Interesting topic for sure, and caused me to refresh my recollection about the Singleton Pattern. But I am still perhaps missing the advantage/difference as compared to global variables or constants? Not trying to argue/debate, just genuinely curious- care to elaborate for the education of others on the board? Regards, -M. Beaven |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|