![]() | Products |
| Home » Technical Support » ElevateDB Technical Support » Technical Articles » Building a Windows CE Application with Lazarus and ElevateDB |

CREATE TABLE "Lists"
(
"Name" VARCHAR(60) COLLATE "UNI_CI" NOT NULL,
"TotalCompleted" INTEGER DEFAULT 0 NOT NULL,
"Total" DECIMAL(20,2) DEFAULT 0.00 NOT NULL
)
DESCRIPTION 'Contains the basic shopping list information'
CREATE TABLE "ListItems"
(
"ListName" VARCHAR(60) COLLATE "UNI_CI" NOT NULL,
"ItemName" VARCHAR(40) COLLATE "UNI_CI" NOT NULL,
"PreferredBrand" VARCHAR(30) COLLATE "UNI_CI",
"AreaName" VARCHAR(30) COLLATE "UNI_CI" NOT NULL,
"ShoppingOrder" INTEGER DEFAULT 0 NOT NULL,
"Quantity" DECIMAL(20,2) DEFAULT 0 NOT NULL,
"UnitPrice" DECIMAL(20,2) DEFAULT 0.00 NOT NULL,
"ExtendedPrice" DECIMAL(20,2) COMPUTED ALWAYS AS Quantity*UnitPrice,
"Completed" BOOLEAN DEFAULT False NOT NULL
)
DESCRIPTION 'Contains the actual items on a shopping list'
CREATE INDEX "ShoppingOrder" ON "ListItems"
("ListName" COLLATE "UNI_CI", "ShoppingOrder")
DESCRIPTION 'Used to shop for a list by area ordering';
CREATE TABLE "Areas"
(
"Name" VARCHAR(30) COLLATE "UNI_CI" NOT NULL,
"Description" CLOB COLLATE "UNI_CI",
"ShoppingOrder" INTEGER DEFAULT 0 NOT NULL
)
DESCRIPTION 'Contains all areas used for grouping list items together'
CREATE TABLE "Settings"
(
"ListName" VARCHAR(60) COLLATE "UNI_CI"
)
DESCRIPTION 'Contains the current list name'
ALTER TABLE "Lists"
ADD CONSTRAINT "Name" PRIMARY KEY ("Name");
ALTER TABLE "ListItems"
ADD CONSTRAINT "ListName_ItemName" PRIMARY KEY ("ListName", "ItemName");
ALTER TABLE "Areas"
ADD CONSTRAINT "Name" PRIMARY KEY ("Name"),
ADD CONSTRAINT "ShoppingOrder" UNIQUE ("ShoppingOrder");
ALTER TABLE "ListItems"
ADD CONSTRAINT "ListName" FOREIGN KEY ("ListName")
REFERENCES "Lists" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION,
ADD CONSTRAINT "AreaName" FOREIGN KEY ("AreaName")
REFERENCES "Areas" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE "Settings"
ADD CONSTRAINT "ListName" FOREIGN KEY ("ListName")
REFERENCES "Lists" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION;
Now that we have our database defined, we can now proceed with creating the application. We'll be using Lazarus 0.926 for this application, and we will start by creating a new application project in the IDE. After we have our empty project, we now need to create a data module that will contain the database components and the code necessary to make sure that the database is set up properly.{ TShoppingDataModule }
procedure TShoppingDataModule.DataModuleCreate(Sender: TObject);
begin
{ Activate the engine. The engine can also be referenced by the generic
Engine variable in the edbcomps unit }
ShoppingEngine.Active:=True;
{ Now connect the session }
ShoppingSession.Connected:=True;
{ Check to see if the database exists or whether it needs to be
created }
with ConfigurationQuery do
begin
SQL.Text:='SELECT * FROM Databases WHERE Name='+
Engine.QuotedSQLStr('Shopping');
Open;
if (RecordCount=0) then
begin
{ Database doesn't exist and we need to create it }
Close;
SQL.Text:='CREATE DATABASE "Shopping" PATH '+
Engine.QuotedSQLStr(ExtractFilePath(Application.ExeName)+'data');
ExecSQL;
end
else
Close;
end;
{ Now we can open the Shopping database and start to check the metadata for
the database. If anything is missing, we create it now in the proper order
so as to respect any foreign key <--> primary key RI relationships.
NOTE the use of doubled-up single quotes when embedding string constants in
the SQL. }
with CatalogQuery do
begin
SQL.Text:='SELECT * FROM Information.Tables WHERE Name=''Areas''';
Open;
if (RecordCount=0) then
begin
Close;
SQL.Clear;
SQL.Add('CREATE TABLE "Areas"');
SQL.Add('(');
SQL.Add('"Name" VARCHAR(30) COLLATE "UNI_CI" NOT NULL,');
SQL.Add('"Description" CLOB COLLATE "UNI_CI",');
SQL.Add('"ShoppingOrder" INTEGER DEFAULT 0 NOT NULL,');
SQL.Add('CONSTRAINT "Name" PRIMARY KEY ("Name"),');
SQL.Add('CONSTRAINT "ShoppingOrder" UNIQUE ("ShoppingOrder")');
SQL.Add(')');
SQL.Add('DESCRIPTION ''Contains all areas used for '+
'grouping list items together''');
ExecSQL;
end
else
Close;
The general design goal with the main interface was that the interface should be simple and easy to use and allow someone to immediately be productive. With that in mind, a data-aware TDBGrid component was used for holding the shopping list items. We want the grid to display the shopping list items in the order defined by which area each item can be found in, and we also want the user to see the name of the area as they move from item to item. The following image shows the main interface.
We also needed a way to allow the user to add, edit, and delete the various areas used to group items by the area of the store in which they are found. We did this by adding a separate dialog, as shown below. The areas lookup table dialog is accessible from the main menu via the Preferences menu item on the right.
We use main menu items to give the user the ability to add new shopping lists, or to switch to a different list.
1) Download the project contents using the link below and unzip the container .zip file into the folder of your choosing, making sure to preserve the relative folder structure of the .zip file contents.
4) In the device emulator, use the File Explorer to create a new folder off the root My Device called "Shopping", and underneath it another folder called "data".This web page was last updated on Wednesday, January 13, 2021 at 12:15 AM | Privacy Policy © 2025 Elevate Software, Inc. All Rights Reserved Questions or comments ? |

