IT

Cards (248)

  • Steps to Study

    1. Variables are used as holders to store values entered by the user for later use
    2. Variables receive values on the left of the assignment statement (:=)
    3. Right side gives to the left side of the :
    4. A variable cannot give a value before it receives a value
    5. Always keep input, processing and output separate using //comments
  • Naming Convention

    • Start with the first letter of the data type (r, s, i, b, c, d) as a lowercase letter
    • Follow with a short descriptive name, starting with a capital letter
  • Data Types
    • Real
    • Integer
    • String
    • Boolean
    • Char
    • Date
  • Real
    • Numbers with decimal values
    • Rand values are always stored as real
    • Answers of /, SQRT, Power and RoundTo are always Real
  • Integer
    • Numbers with no decimal values
    • Number of people, age, grade etc.
  • String
    • Any words, special characters and combinations of characters and numbers
    • All cellphone numbers, ID numbers, barcode numbers and other numbers in which we are not interested in the numerical value of
    • Numbers that start with a 0 that is important to keep
  • Boolean
    • Only True or False is stored
  • Char
    • A single character is stored
  • Date
    • Date that you would like to store
  • Declare variables

    Between the procedure heading and the begin
  • Procedure
    1. Declare variables
    2. Begin
  • Variable types

    • iNum: Integer
    • iPeople: Integer
    • iCars: Integer
    • sName: String
    • sSurname: String
    • sInput: String
    • Cost: Real
    • dDOB: TDate
    • cInitial: Char
    • bPaid: Boolean
  • Number data types

    • Integer
    • Real
  • If the code on the left and the right of the assignment statement (:=) are not compatible
    The program will produce an error when trying to run it
  • The following code will produce the error "Incompatible types', because on the left is an Integer variable and on the right the text property of the Edit, is a String data type
  • Type casting

    Converting input from a String to an Integer / Real variable
  • Storing an Integer
    • iNumber:= StrToInt(edtinput.Text);
  • Displaying numbers

    The data type needs to change from an Integer / Real data type to a String to be able to display these numbers
  • Displaying an Integer
    • edtOutput.Text:= IntToStr(iNumber);
  • Type casting

    Always start with what the data type is on the right of the then a to followed by the data type you want to change the value to. This will match the variable data type on the left of the :.
  • Use Appendix B that contains summary of these functions while coding.
  • Input examples
    1. Integer e.g.: iGoals := StrToInt(edtGoals.Text)
    2. Real e.g.: rWorth:= StrToFloat(cotWorth.Text)
    3. String e.g.: sInput: edtinput.Text
    4. TDate e.g.: dNext:= dtpNext.Date
  • Output examples

    1. Integer e.g.: IblOutput.Caption = '+ IntToStr(iNum)
    2. Real e.g.:redOutput.lines.Add('IT: + FloatToStrF(rPerc,ffFixed,10,1)+"%")
    3. TDate e.g.: IblOutput.Caption = "Date: + DateToStr(dDOB)
  • Run the programs often to test the code completed so far.
  • Examples of output is provided to help you test your program. Your program must match the output given exactly.
  • DateTimePicker
    A control that allows the user to select a date
  • TDate
    A data type used to store a date
  • Getting user input for a date

    1. User selects date from DateTimePicker
    2. Date is stored in TDate variable
  • June 2021
    2021/06/19
  • Calendar
    • Sun Mon Tue Wed Thu Fri Sat
    • 30 31 1 2 3 4 5
    • 6 7 8 9 10 11 12
    • 13 14 15 16 17 18 19
    • 20 21 22 23 24 25 26
    • 27 28 29 30 1 2 3
    • 4 5 6 7 8 9 10
  • Today: 2021/06/19
  • Getting today's date

    1. Use Date function
    2. Convert to string with DateToStr
  • Date function returns a TDate data type
  • FormatDateTime
    Function to display a date in a specific format
    • First argument is a format string using y, m, d
    • Second argument is a TDate value
  • FormatDateTime formats

    • yyyy-mm-d
    • dd mmmm yy
  • dd and d differ in how they display single digit days (with or without leading 0)
  • Reset button

    Used to set the Form back to the state it was in when the program started. All objects need to be cleared on the Form.
  • Resetting the Form
    1. Set the cursor in the top left Edit on the Form
    2. Clear Edits and RichEdit using .Clear
    3. Clear SpinEdits by setting the Value property to 0 or another integer number
    4. Set DateTimePicker to today's date using the Date function
    5. Clear a Label by setting the Caption property to an empty string
    6. Set Boolean properties of objects to True/False depending on the state the object was in when the program ran for the first time
  • The table under Appendix A: Object Summary contains code to be used in the Reset button.