Tuto WINDEV 25

Part 7: Advanced programming 429 4.  The class WLanguage code is displayed in the code editor. The declaration code of the class is as follows: cSavanna is Class PROTECTED // Name of Image control used for the drawing m_sNameImageControlForDrawing is string // List of savanna animals m_arrTheAnimals is array of cAnimal dynamic END In this code: • "cSavanna" is the class name. • "m_sNameImageControlForDrawing" and "m_arrTheAnimals" are class members. • The "PROTECTED" keyword is used to specify that these members can only be handled from a code of the class or from a code of a derived class. Describing the methods ▶ WINDEV allows you to easily declare the classes from the "Project explorer" pane. To create a method: 1. Right-click your class in the "Project explorer" pane. 2. Select "New method" from the popup menu. 3.  In the window that is displayed, specify the method name and validate. 4.  Type the method code in the code editor. ▶ To display the AddAnimal method of cSavanna class: 1. Click your class in the "Project explorer" pane. 2. Click the little arrow found in front of the class name: the different class methods are displayed. 3. Double-click the method name: PROCEDURE AddAnimal(pclAnAnimal is cAnimal dynamic) // No more than 5 animals IF m_arrTheAnimals..Count = 5 THEN Error("No more than 5 animals!") RESULT False END // Adds the animal to the list Add(m_arrTheAnimals, pclAnAnimal) // Draws the savanna DrawSavanna() RESULT True

RkJQdWJsaXNoZXIy NDQ0OA==