You are on page 1of 11

INF2611 Exam Preparation Notes 2014 Semester 2

Chapter 9 Menus and Actions


Menus provide lists of items on which the user can click to invoke different program operations. They are usually
displayed only at the users request and therefore help to simplify user interfaces. Without menus, the display or
form would be cluttered with buttons and other components required to trigger the different operations. Menus
provide a concise way to give the user access to a large number of operations.
MENUS
Main menu bar

This is the main menu bar which is displayed across the top of the form directly below the
caption (or title bar. It includes a set of choices called menu titles.
Delphi Summary (pg. 257)A list of menu titles that have drop-down menus associated with them. It is usually
placed horizontally across the top of a window.
Three types of menus exit:
Drop-down menu
Each menu title from the main menu bar provides access to a drop-down menu comprising a
collection of menu items.
Delphi Summary (pg. 257)Choosing a menu title on the main menu bar can open up a list of related options.
This list is a drop-down menu (also referred to as a pull-down menu)
Characteristics of Main Menu Items
1. Menu items can include an underscored character (an accelerator key) that gives the user access to the
menu items through an accelerator key combination of Alt key plus underscored character (e.g. <ALT + O> to
Open a file)
2. Some menu items have ShortCuts that do not require the menu to be visible in order to activate / use them
(e.g. <CTRL + S> for Save).
3. An ellipsis (three dots) next to a selected menu item (e.g. Save As) represents that a dialog box requiring
additional information from the user will appear.
4. A menu item with a small right-pointing arrow next to it represents a cascading submenu which might have
more options (e.g. Reopen)
5. A menu item can be dimmed which represents that the option is currently unavailable.
6. Groups of options on a drop-down menu can be separated with horizontal lines called separator lines.

Main Menu

Cascading Menu
Refer to characteristic 6

Cascading menu This menu is sub-menu of a main menu item and can contain more options.
Delphi Summary (pg. 257)A submenu that can be opened by clicking on (or pointing to) an item on a drop
down menu or a pop-up menu that has a right-pointing arrow as indication.
Pop-up menu This menu is sub-menu of a main menu item and can contain more options.
Delphi Summary (pg. 257)A menu that appears when the user clicks on a control with the right mouse button.
To associate a pop-up menu with a specific component, we assign the name of the
PopupMenu to the components PopupMenu property

Page 1 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Adding a Main Menu Bar
1. Add the MainMenu1 (TMainMenu) component to the form
2. Double click on the MainMenu (name should be mnu) icon on the form to open up the Menu editor
3. Start typing in the name of the first menu item for your new menu
(N.B. You can make use of ACCELERATOR KEYS here)

4. Continue adding further menu items as required


(N.B. You use the INS key to add menu items and the DEL key to remove menu items)

Adding Code to a Menu Item


1. Double click on the MainMenu (name should be mnu) icon on the form to open up the Menu editor
2. Double click on the require menu item causing Delphi to open up an empty Event Handler
3. Add the required code
SHORTCUTS VS ACCELERATOR KEYS
The key difference between an Accelerator key <Alt + O for Open> versus Shortcuts <Ctrl + S for Save> is that
Accelerator keys require the menu and menu items being accessed to be visible. As per our original screen, to use
the Accelerator key <Alt + O for Open> we would have to first press <Alt + F for File> then press <Alt + O for Open> A 2 step process. To use the Shortcut <Ctrl + S for Save>, we just have to press <Ctrl + S> - A 1 step process.
Uses of Menu
Main menu bar Easy display for available options
Drop-down menu List available menu items from the main menu
Cascading menu List available sub-menu items from the drop-down or pop-up menu items
Pop-up menu Provide certain number of choices relevant to the object that is clicked

Summary Notes
&New This will only assign the accelerator key <ALT + N> (known in Delphi as the Accelerator key) to the New
option.
&Save Ctrl + S You have to use the MenuItem ShortCut Property to assign this Shortcut key.

Page 2 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Chapter 15 Introduction to database programming
Database An organized collection of related data. This data is generally stored separately from the application.
Data is stored in tables with rows containing records and columns contain fields. Two types of
databases are common:
local database stored on a single machine
client/server database stored on a file server whereby multiple users can have access
database application A program or collection of programs that manipulate data in a database. Typically reads
information in a database, adds records, deletes records, or changes existing information.
Accessing databases through client software ensures that the users do not corrupt the database.
DATAACCESS COMPONENTS
SQLConnection The SQLConnection component is responsible for connecting the application to the database. It
makes use of two files:
Dbxdrivers.ini lists the installed driver types, lists the DLL libraries / shared objects as well as
default settings for connection parameters
Dbxconnections.ini lists named sets of connection configurations on Windows computers
SQLDataSet The SQLDataSet component converts requests from the application for data, into SQL queries to the
database. The SQLDataSet component can only be used after a connection has been established to
the database through the SQLConnection component.
Has two main properties:
CommandType can be set to ctTable, ctQuery or ctStoredProc
CommandText can be a table name, an SQL query or a stored procedure name
Uses SQL query statements to retrieve records from database to which it is connected.
DatSetProvider Used to provide data from the SQLDataSet to the ClientDataSet and to resolve updates.
ClientDataSet reconstructs the data to create a local, in memory copy for user access. ClientDataSet
repackages changed data and sends the updates back to the provider.
ClientDataSet The ProviderName property of the ClientDataSet must be connected to the DataSetProvider. This
results in the read-only, unidirectional contents of the SQLDataSet to be collected and placed inside
the ClientDataSet component.
DataSource The DataSet property of this component should point to the ClientDataSet component, and all visual
data-aware components can connect their DataSource property to the DataSoource component in
order to get access to the data from the SQL Query on the database.
DATA CONTROL COMPONENTS
Data control components are used to display the data on the screen at run time.
DBGrid Can display several records of a database table (or the result of an SQL query) simultaneously on a form. Is
associated with data through its DataSource property. The value of this property must be the name of a
DataSource component on the form. DBGrid can be used to add new records, delete records or edit fields of
existing records.
DBEdit Used to display one record at a time as opposed to a tabular format like DBGrid. Uses the DBNavigator data
control to navigate between records. Displays only one field of a DataSet record per DBEdit component. You
use the DataField property to display the associated field.
DBNavigator Consists of a series of buttons that the user can use to move through the records in the database one
at a time, insert and delete records, move to the beginning or end of the database, and so on.
To apply updates to the database you have to use the ClientDataSet.ApplyUpdates(0); method
We can use the ClientDataSet.ChangeCount > 0 property to see if any changes have been made. This will save
unnecessary calls to the ApplyUpdates method.
Page 3 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


To provide an undo option to the user, we use a BitBtn component with a name of bmbUndoLastChange, its kind
property set to bkRetry and its caption property set to Undo last change. We use the
ClientDataSet.UndoLastChange(True); method to perform this task.

Chapter 16 Database programming using data modules and multiple forms


Modal Form Display the form using the frm.ShowModal method
Does not allow the user to switch between forms requires the form to close first
When displayed is the only form that can accept input from the user
Examples of Modal Forms are ShowMessage and InputBox
This method is best suited for Dialogs which require user input before proceeding
Modeless Form - Display the form using the frm.Show method
Allows the user to switch between forms application can continue in parallel (i.e. simultaneously)
Allows user to operate all other loaded forms operations
This is the preferred method
Data Module This is the best place to store our Database objects / components so that multiple forms can access
the data from one central location.
For centralized handling of all data components.
Prefix: dmo
Components that we add to a Data Module SQL Lite
SQLConnection We need at least one of these components per a database
(N.B. One Database can consist of many tables, each table can consist of many records and fields. We generally
only want to connect to one database per application)

Prefix: sco
Use: Contains the database connection information

DataSource We need one per table


Prefix: dat
Use:Provides a connector between the data set and the data controls on a form that enable
display, navigation and editing of data

SQLQuery We need one per table


Prefix: sds
Use: Contains the query information, e.g.: SELECT * FROM dbo

SQLTransaction we need one per table


Prefix: sqlTransaction1

Page 4 of 11

INF2611 Exam Preparation Notes 2014 Semester 2

Components that we add to a Data Module Delphi Textbook (pgs. 409 412)
SQLConnection We need at least one of these components per a database
(N.B. One Database can consist of many tables, each table can consist of many records and fields. We generally
only want to connect to one database per application)

Prefix: sco
Use: Contains the database connection information

SQLDataSet We need one per table


Prefix: sds
Use: General-purpose unidirectional data set for accessing database information. Presents
information from a table of the database. Can be used to execute a stored procedure. Uses
the following properties:
SQLConnection - required
CommandType type of command
CommandText stored procedure or select

DataSetProvider We need one per table


Prefix: dsp
Use: Used to provide data from data set to a client data set.

ClientDataSet We need one per table


Prefix: cds
Use:Represents an in-memory or local data set

DataSource We need one per table


Prefix: dat
Use:Provides a connector between the data set and the data controls on a form that enable
display, navigation and editing of data

Data Controls Displays data from a database source, such as a Table, outside the application.
Can be used to optionally post data changes back to database.
Each data-aware control needs to be associated with a DataSource component in order for the
control to receive or manipulate data
Examples of Data Controls are: DBEdit, DBGrid, DBNavigator, DBComboBox

Page 5 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Data aware controls Controls which have the ability to automatically display the components of the contents of
the database records
DBText Used to display the contents of a field in the current active record of a data set.
Cannot be modified by user

Chapter 18 Investigating objects


Object-oriented (OO) programming is currently the best approach available for dealing with many problems facing
software developers. There are plenty of object-oriented development tools available today. Many systems analysts,
designers and programmers require understanding of object orientation. Just about everything you can think of in
Delphi is an object from the Form to the various components.
CLASSES AND OBJECTS
The figure below represents the classes and objects that Delphi automatically creates/generates for us.

Firstly take note that Delphi writes all its code in a unit file. This unit file consists of three sections:
Unit name In our example above, the unit name is MyClassObjectExample_u.
Interface section In our example above, the interface section is lines 5-20. This section provides the link between a
particular unit and other units. Permits communication between other units. The interface
section can be broken down into three further subsections:
Uses clause lines 7-8, tells Delphi how to interact with operating system, how to create forms
and components. Most of this information is stored in additional unit files which
form part of the standard Delphi toolset. An example is:
SysUtils Allows the use of many built in Procedures and Functions such as StrToInt
(String to Integer conversion) and TimeToStr (Time to String conversion)

Page 6 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Type declaration lines 10-16, this is where we store our Object-Oriented (OO) programming
language types or classes. Line 11 shows us that we are deriving a new
class, called TfrmMyForm, from the standard Delphi class Tform
var (variable)declaration lines 18-19, this is where the objects of the available class types are
defined. As you will see we have class TfrmMyForm and an object of
this is frmMyForm.
N.B. DELPHI SHOWS THE DIFFERENCE BETWEEN TYPE AND OBJECT BY
PLACING A T IN FRONT OF THE TYPE

Implementation section This is where we right our program code. This section is private to the unit and describes
the inner workings of all the types declared in the type declaration. We can place the uses
clause here
N.B. DO NOT DELETE THE LINE {$R *.Lfm} Lazarus, {$R *.DFM} Delphi 7, {$R *.nfm} Delphi 8 AS THIS IS A SPECIAL INSTRUCTION TO THE COMPILER. IT IS A RESOURCE DIRECTIVE
THAT TELLS THE COMPILER TO INCLUDE THE FORM FILE IN THE APPLICATION.

Class A class can be seen as a template for making something. We cannot use a class directly but a class has the
necessary information to make something that we can use. A class can contain one to many objects, one to
many functions, one to many procedures or one to many methods.
Objects - Objects are sometimes referred to as an instance (of a class). They contain properties which are unique to
itself. An object is a self-contained entity that encapsulates its own data and methods. Objects keep helper
and data methods private so as not to interfere with other objects. Access methods are public so that other
objects can have access.
SIMPLE OBJECT ORIENTATION (OO)
Object-oriented and traditional procedural programming share a common set of programming fundamentals:
1. Sequential execution of program statements
2. Variables, expressions and assignment
3. Structured constructs such as conditional evaluation (e.g. If, Case) and iteration (e.g. While, Repeat, For)
4. Input and output management
5. Subroutines
6. Addressing, Indexing, Pointers
BASIC OBJECT ORIENTATION (OO) PRINCIPLES
An object is a self-contained entity that has state and behaviour through its attributes, methods and properties. Here
are the three fundamental characteristics of Object Orientation (OO) that are supported through a full Object
Oriented (OO) language:
1. Encapsulation Each object holds its own data and is unique to that object (in Delphi these are referred to
as properties of a control). Other objects do not have access to the data held by an object
and can only pass a message to the other object requesting the appropriate action.
Alternative summarized version (Extra notes from M.Kies)
Encapsulation means that a class publishes only what is needed for others to use it, and no
more. This is called information hiding and it means the internal coding of classes can be
changed classes without having an effect on code that uses the class and its methods.
2. Inheritance Objects lower down the hierarchy inherit data and behaviour from their ancestors in the
higher up hierarchy
3. Polymorphism An object can operate interchangeably with an ancestor in relation to the attributes and
methods it inherits from the ancestor
Alternative summarized version (Extra notes from M.Kies)
The ability to redefine methods for derived classes. For example, given a base class shape,
polymorphism enables the programmer to define different area methods for any number of
derived classes, such as circles, rectangles and triangles. No matter what shape an object is,
applying the area method to it will return the correct results.
An additional concept associated with Object-Oriented (OO) language is composition. Composition is the principle by
which we can compose an object out of several sub-objects.

Page 7 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Encapsulation Consists of both public interfaces and private sections. The public sections provide communication
paths to other objects and declare a classs capabilities. The private sections describe how the class
performs its capabilities using procedures and functions that make up the methods.

Page 8 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Chapter - Various
Incremental development

Helpful in developing applications in stages, testing each stage before moving to the
next. Sometimes referred to as the divide and conquer approach.
Working with smaller programs helps eliminate the errors by testing the
implementation before moving onto the next stage
By testing smaller programs we eliminate the introduction of multiple errors at one
given point

Chapter 9 Menus and Actions


Reasons to include Menus in applications:
Extra notes from M.Kies
1. Options are constantly available to the user
2. Users can explore choices
3. The user does not need to remember commands to type, but can easily select commands from a menu
4. Menus provide structure and logic to the application. Menus can be used to group similar commands
5. Ease of use
6. Errors are reduced as users can only select from valid choices
7. Menus are commonly used in applications so users are familiar with its operation

Reasons NOT to use Menus in applications:


1. Menus require the user to know or understand the functions of the options
2. Complex systems could result in too many menu items complicating navigation
3. Menu driven systems are more rigid
End of Extra notes from M.Kies

Menu components and their uses


Menu components by F.Marshman, Menu uses by D.Van Graan
Main Menu bar
Description: Is a list of menu titles that have drop-down menus associated with them. It is usually placed horizontally
across the top window
Use: You would use a main menu if you intend to use further drop-down menus
Pop-up menu
Description: A menu that appears when a user clicks on a control with a right mouse button
Use: You would use a pop-up menu for quick access to items that are used often
Drop-down menu or Pull-down menu
Description: Choosing a menu title on the main menu bar can open up a list of related options
Use: You would use a drop-down menu to add more selections
Cascading menu
Description: A submenu that can be opened by clicking on an item on the drop-down menu or that has a rightpointing arrow as indication
Use: You would use a cascade menu if you have selections that branch off the main selections in a drop-down
menu, thus organizing or categorizing the menu
Checkmarked menu
Description: When a menu item toggles between 2 states e.g.: Bold/Not Bold. We can use its checked property to
indicate the current state of the menu item
Use: You would use a checkmarked menu if the data has only two options that require you to toggle between them.

Page 9 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Chapter 16 Database programming using data modules and multiple forms
MULTIPLE FORMS
Extra notes from M.Kies
auto-create forms These are always created when an application is run and the programmer does not need to
use the constructor to create the forms before they can be displayed.
available forms -

These are not automatically created and the programmer are required to use a constructor
to instantiate the object before it can be referenced.
End of Extra notes from M.Kies
Factors to consider when deciding to use multiple forms:
1. Do you want the user to switch between forms (Modeless Form)?
2. Do you want the user to make a choice/selection/decision on the form before continuing to the next form
(Modal Form)?

Reasons to include Multiple Forms in applications:


Extra notes from M.Kies
1. Each form can be used to deal with different types of data or processing in an application.
2. It logically groups processing together
3. Multiple forms allow users to work with more than one form at a time if used in modeless form
End of Extra notes from M.Kies
4. Displaying different datasets from multiple tables
MODAL FORMS
Extra notes from M.Kies
Modal forms are used where the application cannot continue until the user has provided the required information.
You want to force the user to deal with the form before continuing to use the application.
End of Extra notes from M.Kies
DATABASE APPLICATIONS
Extra notes from F.Marshman
Data-aware controls These components automatically display the components of the contents of the database
records. They can record content from the database and display and modify the results of
the user record and at the same time be saved back to the database. The DBGrid is used for
this.
DBEdit is the most commonly used data-aware component and display the contents of the
field, but also modify the results of the user's saved to the database, e.g. DBEdit display the
data in the table.
A separate navigation component , the DBNavigator data control, to link onto the
ClientDataSet-DataSource chain. The DBNavigator component consists of a series of buttons
that a user can use to move to the beginning or end of the database. The DBNavigator
component is also linked to the appropriate database through its DataSource property.
End of Extra notes from F.Marshman

Page 10 of 11

INF2611 Exam Preparation Notes 2014 Semester 2


Chapter 18 Investigating objects
CLASSES AND OBJECTS
Extra notes from M.Kies

Object
An object is a self-contained component that contains properties and methods needed to make a certain type of
data useful. An objects properties are what it knows and its methods are what it can do. For example, a project
management application can have a status object, a cost object, and a client object, among others.
One property of the status object would be the current status of the project. The status object would have a method
that could update that status. The client objects properties would include all of the important details about the
client and its methods would be able to change them. The cost object would have methods necessary to calculate
the projects cost based on hours worked, hourly rate, materials cost, and fees.
Objects are the fundamental building blocks of applications from an object-oriented perspective. Many objects of
many different types in any application are used in development. Each different type of object comes from a specific
class of that type.

Class
A class is a blueprint or template or set of instructions to build a specific type of object. Every object is built from a
class. Each class should be designed and programmed to accomplish one, and only one, thing. Because each class is
designed to have only a single responsibility, many classes are used to build an entire application.
For example think about classes like baking a cake. A class is like a recipe for chocolate cake. The recipe itself is not a
cake. You can't eat the recipe (or at least wouldn't want to). If you correctly do what the recipe tells you to do
(instantiate it) then you have an edible cake. That edible cake is an instance of the chocolate cake class. You can bake
as many cakes as you would like using the same chocolate cake recipe.
End of Extra notes from M.Kies

Page 11 of 11