It Grade 12 Notes
It Grade 12 Notes
● When creating a class, the first thing you do with your application is create a new unit
file
○ You then want to rename the file to something that makes sense/suits the
program you care creating
● Once you have opened a unit file, you want to create a new object. This object will
take the characteristics of the parent object, so you assign it to class(tObject)
○
○ Methods are things that your object is able to do. For example think of a car, its
methods would be driving forwards and backwards, shining lights, playing music
ect. Methods don’t really have naming conventions as they are
functions/procedures
○ Methods are declared under the public section on your unit file. This basically
means that your main form IS able to access/work with the methods your object
is able to carry out.
○
● There are 3 types of methods:
○ GETTER METHODS / ACCESSOR METHODS - Always functions that are used
to receive the attributes of the object as a variable/results
○ SETTER METHOD / MUTATOR METHODS - Always Procedures that are used
by your main form to indirectly change the attributes of your main form
○ AUXILIARY METHODS - Methods which can be either procedures or functions
and have the main function of making calculations
● To add an object to your main form add the class name under the uses heading in
the code of the main form
○
● To create an object using your class, assign a variable to your class name
○
● To use the methods your object consists of, you would write objectname.method
similar to how for a TEdit you could use the .text method, or for a TSpinEdit you could
use the .value method
○
Databases:
SQL:
● SQL stands for structured query language and is one of the most common ways
developers query a database
● To use SQL:
● First select which field(s) you are going to be looking at and displaying in the
database. Fields are separated by a comma
○ SELECT First_Name, Last_Name
● Thirdly, determine which condition you are looking for. This can for example be
checking whether the value in a field is equal to a condition or greater than/less
than a set value. You separate conditions with an AND, and words are placed
between quotation marks and dates are placed between hashtags while
integer values are just written out as is
○ WHERE Gender = “Female” AND DOB > #10/09/2004#
● Finally you determine the way you would like to order your fields. You write this in
full capitals and go ORDER BY (FIELD)
○ ORDER BY DOB
● In SQL, there are certain characters known as wild cards. Wild Cards can represent
any character. There are 2 main types of wild cards:
○ ( _ ) an underscore is a wild card which represents a single character. For
example ‘__Jassem’ would mean that any word containing 2 characters before
Jassem is valid
○ ( % ) a percentage sign is a wild card which represents an undefined number of
characters. For example ‘%@gmail.com’ would mean that any word which ends
with @gmail.com, regardless of how many or what type of characters are before
it is valid
○ When using wildcards you use the word like instead of the = symbol
○
● When working with a set, so a group of values, you don’t use the = sign, but rather the
IN function
○ The basic format of the function is: WHERE Name IN
(“Jassem”,”Jean”,”Alex”)
○
● If you would like to order the records by a certain field you use the Order By function
○ The format is: Order By Field ASC/DESC
○ The asc stands for ascending and orders the records in ascending order based
on the field and desc stand for descending and does the opposite
○ If you would like to order records by more than one field you use Order By Field
ASC, Field DESC for example which orders the records first by the original field
and then by the secondary field
■ For example if your first field was a company name and the second was
the product description, it would first order all the records by the company
name with the closest letter to a, and then would order the now ordered
fields once more by the product names with the closest letter to z
■ This doesn’t mean it re-orders everything, and the records will still be
ordered by company name, it will just then also be ordered by the product
names after
● If you would like to select only records that are unique from one another when looking at
the selected fields use the SELECT DISTINCT function in your sql statement
○ This replaces the select function that is normally used in sql
○ The line: SELECT DISTINCT PersonName, Surname, School would only
display records where either the persons name, surname or school is different
■ If there were 2 John Doe’s for example, but they go to different schools
the record would still be displayed but if they went to the same school, the
record would only be displayed once
● If you’re working with more than 1 table simultaneously, so a parent and child table, you
will have 2 tables in your ‘FROM’ statement
○ You then need to specify from which table are you taking the shared field, so are
you taking it from the parent key where its a primary key or from the child table
where its a foreign key
○ You also need to check that the primary key and foreign key in both tables
is the same to ensure that you’re getting information that relates to one
another
○
○ Notice how I reference which table I’m working with (circled in blue) by writing the
table name, dot and then the field name. You can shorten this by typing the
table name, a space and then a value you’d like the table to be referenced
as in your FROM statement
○
● If you would like to count how many records there are that match your SQL
statement:
○ You can firstly loop through your Query component similarly to how you would a
table. So QueryNAME.first; While Not QryNAME.EOF do and then you have a
variable you increment with each loop and go to the next record
■
■ Here the variable iCount would be the value of the number of records
which match your SQL statement, not all the records in the table
■ You need to use this method in exams
● If you would like to perform a calculation with 2 fields in an SQL statement directly
○ First you need to state which 2 fields you are working with and then minus, add,
divide or multiply them
○ Second you need to give this new field you’ve created a name. Put the name in
square brackets with the word AS before it
■
○ Note you’re not able to refer to this field in your sql statement, you’d have to use
the original 2 fields with the arithmetic symbol present
■
● When giving a field you have worked with whether that may be through using functions
or arithmetics a new name using the AS function:
○ You can't work with the new field in your SQL statement
■ For example when trying to use the group by function, or when using a
conditional statement like where ect.
○ You can however work with the field in your query component so to display
it on outputs
■ For example RedOut.Lines.Add(qryExcursion[‘NewFieldName’])
🔍EXTRA NOTE
Whenever you are using an aggregate function like count, or sum ect:
- You ALWAYS need to group the aggregate function, or the fields used in the
aggregate function, by another field that isn’t being used in the aggregate function
- This ensures that the answer of the aggregate function isn’t output multiple times as
the full amount, else you’d get an error with your code
- EXAMPLE: SELECT Register class, SUM(AmountPaid) AS [Total Amount] FROM
Learners GROUP BY Register Class
- If you’re using more than 1 field in the select statement, you have to group by one of
the fields in your select statement, but if you’re only working with an aggregate
function field you can group by anything
🔍EXTRA NOTE
If you have 2 fields in a table that you would like to turn into 1 field:
- You can add the 2 field names together and then rename the field
- For example: SELECT RegisterClass + “.” ActivityName AS [Class Activity]
- You will then have a field called Class Activity in your SQL statement that is a
combination of the field Register Class, a fullstop and the field ActivityName
SQL FUNCTIONS:
● FORMAT FUNCTION: (SELECT ….. FORMAT(.......) AS [Name of new field])
○ To Format Currency: FORMAT(TotalPaid *+-/ 0.25, “Currency”)
○ To Format Dates: FORMAT(DateOfBirth, “dd-mmm-yyyy”)
■ 3 d’s will give you the day as a 3 letter word (Tue, Mon, Wed)
■ 3m’s will give you the month as a 3 letter word (Jan, Feb, Mar)
■ 1 d will give you the date as 1 or 2 numbers(1, 12, 24)
■ 1 m will give you the month as 1 or 2 numbers( May = 5, Dec = 12)
■ 2d’s will give you the date as 2 numbers always (01, 05, 12)
■ 2m’s will give the month as 2 numbers always (May = 05, Dec = 12)
■ 4 y’s gives you the full year (2015, 2024)
■ 2y’s gives you the last 2 digits of the year (15, 24)
■ Having dashes or forward slashes determines how number are split and
having none will just leave spaces(12/05/2026 OR 12-05-2026 OR 12 05
2026)
○ To Format A Number To 2 Decimals: FORMAT(LongNumber,”Fixed”)
○ To Format A Time: FORMAT(TimeOpened, “hh:mm AM/PM”)
🔍EXTRA NOTE
🔍EXTRA NOTE
○ Second: You add a bracket after the table name, and write all of the different
names for the fields in your database
■ ‘(FieldName1, FieldName2, FieldName3, FieldName 4)’
○ Third: You write VALUES(...) with all the values of the new fields. Its important to
note the order you add these values in is crucial and must line up with your field
order originally
■ ‘VALUES(Value1, Value2, Value3, Value4)’
■ NOTE: The values must be in between the right symbols, so text between
quotation marks, dates between hashtags ect
● Let's say you are selecting fields from a certain record, but you only want to take records
that are corresponding, so primary key in the parent table links with the foreign key in the
child table
○
● If you have a data module(dm) connected to a Database grid (dbGrid) and would like to
work with the selected record on the dbGrid, you can use the
dm[NAME].tblName[‘FieldName’]
○ This will automatically extract the field from the selected record on the dbGrid
○
○ This code will essentially give the variable sActivity the value of ‘Archery’ as that
is the value of the field [‘ActivityName’] for the selected record in tblActivity
Arrays:
● When trying to remove a value from the array
○ First: Find out the total number of entries in the array and store it
○ Second: Assign a value to the position of the entry in the array that you would
like to delete
○ Third: Loop from the position of the entry you would like to delete, till the total
number of entries in the array -1
○ Fourth: Make each entry in the array, the next entry (ArrName[iLoop] =
arrName[iLoop + 1]
○ Fifth: Make the highest entry now equal to nothing, and decrease the total
number of entries
○
ARRAYS:
● You can create 2D arrays in delphi rather simply
○ A 2D array is an array which has 2 different parameters as opposed to just one
○ A 2D array will create a grid of parameters for values
○
1 2 3 4 5 6 7
C John
E
○ For example, looking at this 2D array, if we wanted to insert or work with a
certain value, you would reference it by referencing the block, like a coordinate
○ C6 for example would return the value: John
● To create a 2D array you use the same code when creating a normal array but with 2
Parameters rather than one
○ The array used in this example is called ar2Tip. The variables used for the loops
are cRow, and iCol. These 2 variables will then be the parameters
■ For example when cRow := C and iCol:= 5, then the block C5 would get
populated by the value from the input box
■ The input box is being used to determine what the value for a certain
block should be
● To actually work with your 2D array, for example when trying to calculate the sum of a
single row:
○ You need to once again loop through the different parameters, looping through
the first and then the second in a nested loop
○ You then put your code in your nested loop and repeat
○