Connecting the Forms to the Data-Layer (part 3)
I apologize if I am a bit brisk today, I slipped and fell getting out of my wheelchair today, messed up my Right Knee and left foot.
Any Way Picking up where I left off, our next step to create our database tables. Here is the Solarsystem Table SQL:
DROP Table IF EXISTS SolarSystem ;
Create Table SolarSystem
(
ID INTEGER Not NULL PRIMARY KEY AUTOINCREMENT,
GalaxyID INTEGER ,
Name VarChar(100) NOT NULL ,
GRow INTEGER ,
GCol INTEGER ,
FOREIGN KEY (GalaxyID) REFERENCES Galaxy(ID)
);
And the Galaxy Table SQL:
DROP Table IF EXISTS Galaxy ;
Create Table Galaxy
(
ID INTEGER Not NULL PRIMARY KEY AUTOINCREMENT,
Name VarChar(100) NOT NULL
);
I've decided the BEST way to show all this to you will simply be to Start at the top and Explain each Procedure as it's called, rather then explain them first and hook them up.We have our Data-Layer, Screens, and SQL Tables.
Next Step I'll connect our Application Desktop to the Galaxy Data-Layer table.
Firts I'll add in all the necessary Includes of code at the TOP of the Desktop Control-Loop Code. It's best to use XIncludeFile instead of IncludeFile. XIncludeFile will only load a module ONE time.
Here's the Include Section:
XIncludeFile "Blog_Constants.pb"
XIncludeFile "Blog_Windows.pb"
XIncludeFile "Utils/ComboBoxExModule.pbi"
XIncludeFile "Utils/ListExModule.pbi"
XIncludeFile "Module/DB.pbi"
XIncludeFile "Module/SolarSystem.pbi"
XIncludeFile "Module/Galaxy.pbi"
Global WorkGalaxy.GALAXY::Galaxy
Global WorkSolarSystem.SOLARSYSTEM::SolarSystem
XIncludeFile "Views/frmSolarSystem.pbi"
XIncludeFile "Views/frmGalaxy.pbi"
Declare frmMainCustom()
;- Main Loop
If Window_frmMain()
frmMainCustom()
Define quitfrmMain=0
Repeat
The first two includes are the Form Constants Include and the Form Window Code that I have previously Shown you.
Next, I add in the Utilities ComboBoxEx, and ListEx, then the Modules (Data-Layer)
Then I instantiate our Global Data Objects. a WoorkGalaxy iof type GALAXY::Galaxy, and WorkSolarSystem of type SOLARSYSTEM::SolarSystem.
Then the includes for the View Code or Form Code, where these variables will be used.
Finally I put in a declare for the frmMainCustom Procedure, which will be called immediately after we create the form. This custom procedure is where we can Theme the form and where we swap out the default gadgets with custom Gadgets.
"If Window_frmMain" is the call to present our Application Desktop code, the next line of code calls the form customization procedure. The following is our desktop's customization procedure.
Procedure frmMainCustom()
Protected X, Y, w, H, Flags
;I put the List in a Container so we must open container Gadget List
OpenGadgetList(#Gadget_frmMain_ctrLeft)
;Convert the LidtIcinGadget to ListEX Custom Gadget
X = GadgetX(#Gadget_frmMain_liList) : Y = GadgetY(#Gadget_frmMain_liList)
W = GadgetWidth(#Gadget_frmMain_liList) : H = GadgetHeight(#Gadget_frmMain_liList)
FreeGadget(#Gadget_frmMain_liList)
;Now to create oue ListEx
Flags = ListEx::#AdjustColumns|ListEx::#ResizeColumn|ListEx::#GridLines;|ListEx::#AutoResize
ListEx::Gadget(#Gadget_frmMain_liList, X, Y, W, H, "", 25, "", Flags, #Window_frmMain)
CloseGadgetList()
;Other exchanges we could do are to swap out Buttons, ComboBox to ComboBoxEx
;This is where we can theme your application
EndProcedure
Now that our Desktop is displayed, and customized, we need to call our Data-Layer, in looking at our Application Desk Top we have a ListIcon Gadget which needs to be Loaded with all the Galaxy Records from our Database.
First I'll define a couple helper variables, in Procedures it is a "Best" Practice to use "Protected" rather than Define.
Then I will make a Call to our LoadListIcon Procedure on the Galaxy Module.
Define Index, ID
;This Loads the ListIcon with all Galaxies in the Database
GALAXY::LoadListIcon(#Gadget_frmMain_liList)
To be courteous to our Users , we can select the First Record in the List. We do this with the following Code:
;If there ARE Records select the First
If ListEx::CountItems(#Gadget_frmMain_liList) > 0
ListEx::SetState(#Gadget_frmMain_liList, 0)
EndIf
I'm purposefully going to stop here. To some seeing this first connection between Modules and Procedures can be a bit mind blowing.
I have glossed over the PureBasic Commands up until now, If, you like I can go back and put in the Used commands and define them. Going forward I'll try to remember to put them in.
Commands used in this Post:
GALAXY::LoadListIcon is the ModuleName :: ProcedureName
CountGadgetItems or using ListEx::CountItems Returns the numbers of items in List
SetGadgetState or using ListEx::SetState will SET the selected item in List
GetGadgetState or using ListEx::GetState will return the ZERO Based Item Selected.
Comments
Post a Comment