To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Data Entry Objects
Cancel

Working with databases

Lesson 6: Access data using local buffer

Following is a demonstration of using a local file buffer.

  1. Create a basic Windows project (a project without a user interface)…
  2. From within the DataFlex Studio select the ‘Create New’ icon from the top toolbar.
  3. Select ‘Basic Project.’ Select OK.
  4. Enter “LocalBuffer” as the ‘File Name.’ Select OK.
  5. Create a business process…
  6. A business process is an object in a Windows application that has a Data Dictionary structure to facilitate certain things and to show a status dialogue.
  7. Again, select the ‘Create New’ icon from the top toolbar. 
  8. Select the ‘Other’ tab.
  9. Select ‘Business Process.’ Select OK.
  10. Enter “LocalBuffer” as the ‘Object Name.’ Select OK.
  11. The business process contains an object of the class “BusinessProcess,” and an “OnProcess” event that will contain the logic of what needs to be done. A business process always does something.
  12. Add a line of code by selecting the object, ‘oLocalBuffer,’ from the ‘Code Explorer’ on the left.
  13. From the ‘Properties’ panel on the right change ‘Display_Error_State’ to “True,” so that any errors along the way are shown.
  14. Select VIEW > DDO Explorer from the top menu to open the DDO Explorer panel in the Studio. It will appear on the right side of the Studio.
  15. Note: the DDO Explorer shows the DDO structure. For each table, a Data Dictionary (DD) class is automatically created. The DDO structure is a tree of objects that are created for each table to be used in the application.
  16. Select the ‘Add DDO’ icon from the top of the panel.
  17. Select ‘cRecipeDataDictionary’ form the list. Select ‘Select.’
  18. That DD is added to the DDO Explorer as is the ‘cKitchenDataDictionary,’ which is a parent table.
  19. Expanding ‘cRecipeDataDictionary’ shows that the parent is a server of the Recipe table.
  20. The source now includes both DDs, and that the two objects have been created, ‘oKitchen_DD’ and ‘oRecipe_DD.’
  21. This is a relational model in an object structure.
  22. The main DD of the business process is ‘oRecipe_DD.’ This is typically where most finds are performed if there are several DDs.
  23. Build a find loop using the DDS
    Procedure OnProcess

          Send Clear of oRecipe DD

    Send Find of oRecipe_DD FIRST_RECORD 2


    While (Found)

               Showln (SFormat(“Recipe %1 (Kitchen: %2)”, Field_Current_Value(oRecipe_DD, RefTable(Recipe.Name)), Field_Current_Value(oKitchen_DD, RefTable(Kitchen.Name))))


               Send Find of oRecipe_DD NEXT_RECORD 2

    Loop

    End_Procedure


  24. Before running the sample, the business process needs to be added to the application.
  25. Click over to ‘LocalBuffer.src.
  26. Add a use statement:
    Use LocalBuffer.bp

    Send DoProcess of oLocalBuffer


  27. Select the ‘Run’ icon from the top toolbar. An Output Window appears that now shows the list of recipes.
  28. To add a DD for the ingredients, close the output window, click over to ‘LocalBuffer.bp’ and select the ‘Add DDO’ icon from the top of the DDO Explorer.
  29. Select ‘cIngredientsDataDictionary’ from the list. Select ‘Select.’
  30. That DD is added to the DDO Explorer. Expanding it shows the relation to the server, ‘Recipe.’
  31. Constrains are also added to ‘Recipe’ because this is the main table in the DDO structure, and it is assumed that if child tables are added that they need to be restrained as is the ‘cKitchenDataDictionary,’ which is a parent table.
  32. Expanding ‘cRecipeDataDictionary’ shows that the parent is a server of the Recipe table.
  33. Build a nested find loop to find all the ingredients in the recipe…
    Send Clear of oRecipe_DD

    Send Find of oIngredients_DD FIRST RECORD 2


    While (Found)

          Showln (SFormat(“ - %1 (Kitchen: %2)”, Field_Current_Value(oRecipe_DD, RefTable(Recipe.Name)), Field_Current_Value(oKitchen_DD, RefTable(Kitchen.Name))))


    Send Find of oIngredients_DD FIRST_RECORD 3

    While (Found)

         Showln (SFormat(“ - %1 (Amount: %2)”, Field_Current_Value(oIngredients_DD, RefTalbe(Ingredients.Name)), Field_Current_Value(oIngredients_DD, RefTable(Ingredients.Amount))))


         Send Find of oIngredients_DD NEXT_RECORD 3

    Loop


    Send Find of oRecipe_DD NEXT RECORD 2

                      Loop  



  34. Select the ‘Run’ icon from the top toolbar. An Output Window appears that now shows the list of recipes and all the ingredients for each recipe that is sorted alphabetically.
  35. To conclude: The difference between using the local and global file buffers is the message interface. Another advantage is that in a Windows application with multiple views the local file buffers for the views will always maintain their states. If the views are switched there is no interference between the views.