Tuto WINDEV 25
Part 4: Full application with data 151 Addition into the data file ▶ We are now going to modify the window of product form to manage the addition of a new record. 1. Open the "WIN_Product_form" window in the editor. 2. We will modify the WLanguage code associated with the "Validate" Button control: • Right-click on the "Validate" Button control and select "Code" in the popup menu. • In the "Click" event, replace the existing WLanguage code with the following: ScreenToFile() IF Product..NewRecord THEN HAdd(Product) ELSE HModify(Product) END Close() Let’s take a look at this WLanguage code: • ..NewRecord is used to find out whether the current record must be created. • If HReset was called beforehand, the property returns True (click on "New product") and the record must be created by HAdd . • Otherwise, the current record already exists and it must be modified by HModify . • HAdd adds the record into the data file. This function takes the values in memory and writes the content of file items into the data file itself. The indexes are immediately and automatically updated. In this case, it is the "Product" data file that is updated. Remark The test code of new record can be replaced by HSave . This function is used to check whether the record is already found in the data file, and it allows you to add it or to modify it. The code becomes: ScreenToFile() HSave(Product) Close() 3. Save the modifications by clicking among the quick access buttons. 4. Close the code window (click X at the top right corner of code editor).
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==