I've spent my day working on StoryBook, it's almost ready for release, but I'm putting it aside to continue my blog post.

Picking up where I left off, everyone has a good grasp on what I'm building I now will list the Procedures which Control the linkage between our Data-layer and our GUI layer.  Each form will have its own Control-Loop.

  • SetScreen() - Displays  Form, and loads form from Data-layer object.
  • Create()      - Creates a NEW Data-layer object and calls SetScreen()
  • Modify()    - Modify Find/Loads Data-Layer Object and calls SetScreen()
  • Delete()      - Delete Confirms, then Deletes Data-layer object.
  • SetData()    - SetData() Loads Form User Input into Data-Layer Object
  • Save()         - Save Calls SetData() the attempts to Save Data-Layer Object
  • Close()        - Cleare any used Images, etc. and Set Close Form Variable.
These are the suffixes that append to the table or form names, so these would translate to being GalaxyCreate() or SolarSystemSetScreen().

Now depending on your situation, I have 3 different versions of Process. But regardless of situation these are core Procedures. In the following posts I will show you each of these methods and the how any why I use the ones I do. 

A word, or two on naming conventions, and Project Structure.  Initially everyone's first few projects, all code resides in a single Project Directory on your hard drive. It does not take long for anyone to figure out that lumping all code sheets into one folder only works for very small projects. As your programs grow you learn to divide up the "types" of codes into separate "logical" folders. Everyone does what makes sense to them. Well, this is My Structure:

/Project           - Main Folder
    /Forms        - Forms Folder
    /Images       - Images
    /Includes     - Helper functions
    /Modules     - Data-Layer Code Sheets
    /Types          - Type Code Sheets
    /Utilities       - Custom Modules/Controls
    /Views          - Form Code Sheets  

Up to now, all Code Sheets have been Modules. As a Rule I name them the name of the Table, so now we have a DB.pbi, Galaxy.pbi, and a SolarSystem.pbi.

Now we are building VIEW Code. To keep things straight, I prefix View Code with "frm" then Table Name or form Name. So here we will be creating frmGalaxy.pbi, and frmSolarSystem.pbi.

Our "current" project has NO overarching "Project" or Application Desktop, and I'm going to start there and now create a Desktop for our Project. For lack of a better idea I'll call this project "The Known Universe", Here we have ONE Universe, it contains many Galaxies, each containing some number of Solar Systems.

So here is our Project Desktop. We have a simple list of Galaxies we've created, and the usual Create, Modify, and Delete buttons for use to manage our data. When you Click on the Create Button we will call the frmGalaxy Procedure GalaxyCreate()


Here is the Code:

OpenWindow(#Window_frmMain,0,0,312,654,"Known Galaxy",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    CreateImageMenu(#MenuBar_frmMain,WindowID(#Window_frmMain))
      ContainerGadget(#Gadget_frmMain_ctrToolbar,5,5,295,70)
      ImageGadget(#Gadget_frmMain_imgCreate,5,7,55,55,ImageID(#Image_frmMain_btCreate))
      GadgetToolTip(#Gadget_frmMain_imgCreate,"Create")
      ImageGadget(#Gadget_frmMain_imgModify,62,7,55,55,ImageID(#Image_frmMain_btModify))
      GadgetToolTip(#Gadget_frmMain_imgModify,"Modify")
      ImageGadget(#Gadget_frmMain_imgDelete,120,7,55,55,ImageID(#Image_frmMain_btDelete))
      GadgetToolTip(#Gadget_frmMain_imgDelete,"Delete")
      ImageGadget(#Gadget_frmMain_imgPower,235,7,55,55,ImageID(#Image_frmMain_btPower))
      GadgetToolTip(#Gadget_frmMain_imgPower,"Exit System")
      CloseGadgetList()
      ContainerGadget(#Gadget_frmMain_ctrLeft,30,80,250,500)
      ListIconGadget(#Gadget_frmMain_liList,10,20,235,475,"Names",210,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
      SetGadgetFont(#Gadget_frmMain_liList,LoadFont(#Gadget_frmMain_liList,"Rockwell",14,#PB_Font_Bold))
      CloseGadgetList()
      HideWindow(#Window_frmMain,#False)
And here is our starting Event Loop


;- Main Loop
If Window_frmMain()

  Define quitfrmMain=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #Window_frmMain
            quitfrmMain=1
        EndSelect

      Case #PB_Event_Menu
        Select MenuID
          Case #MenuBar_frmMain_New
          Case #MenuBar_frmMain_Open
          Case #MenuBar_frmMain_Save
          Case #MenuBar_frmMain_Exit
          Case #MenuBar_frmMain_Settings
          Case #MenuBar_frmMain_Help
          Case #MenuBar_frmMain_About
        EndSelect

      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_frmMain_ctrToolbar
            Select EventType()
              Case #PB_EventType_Resize
              Default
            EndSelect
          Case #Gadget_frmMain_ctrLeft
            Select EventType()
              Case #PB_EventType_Resize
              Default
            EndSelect
          Case #Gadget_frmMain_liList
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_LeftClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Case #PB_EventType_Change
              Case #PB_EventType_DragStart
              Default
            EndSelect
          Case #Gadget_frmMain_btCreate
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_LeftClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Case #PB_EventType_DragStart
              Default
            EndSelect
          Case #Gadget_frmMain_btModify
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_LeftClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Case #PB_EventType_DragStart
              Default
            EndSelect
          Case #Gadget_frmMain_btDelete
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_LeftClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Case #PB_EventType_DragStart
              Default
            EndSelect
          Case #Gadget_frmMain_btPower
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_LeftClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Case #PB_EventType_DragStart
              Default
            EndSelect
        EndSelect

    EndSelect
  Until quitfrmMain
  CloseWindow(#Window_frmMain)
EndIf
End



Comments

Popular posts from this blog

PAHLabs Blog goes Live

How to build this without writing Code

Connecting the Forms to the Data-Layer (part 9)