Main Form

Question 3.2 (Q 2.2 in papers from and before Supplementary 2018) is what you need to do in the Main Form.

  1. Make the form accessible to the main form by copying the name of the file (clsLearner_u) to the uses of the main form. This name can be found as the first line of the class next to unit. In the finals this is often done for the learners as part of the given code.
  2. Declare the object variable under private to make it accessible to the whole main unit. For Example: Learner : TLearner; NOTE: an array of objects is no longer part of what we teach. In the finals this is often done for the learners as part of the given code.
  3. The data type of this variable can be found under Type in the class.
  4. Learners will need to get input from the user or input from a text file and store the input as local variables, before they call the parameterised constructor. Make sure that the input is stored in the same data type as is required for the arguments that will be sent to the parameters of the constructor. For example: do not store all the values as strings and then convert inside the line to instantiate the object. It makes it very difficult to sort out errors. There are also often marks allocate for the input before instantiating the object which then needs to be allocated inside the instantiating line and can easily be missed.
  5. Before one can use any method of the class one first needs to instantiate the object. Make sure your learners study this single line of code. If they fail to instantiate the object, they will not get output for this question. There are many ways to instantiate the object which will not give a syntax error. To assist in using the correct method, for our papers, copy the declaration of the object and paste it where you need to instantiate. For Example: Learner : TLearner. Add the = to form an assignment statement. For Example: Learner := TLearner and then add the .Create and it's arguments. Learner := TLearner.Create(sName,sDOB,rMark); Remember the arguments need to match the parameters of the Constructor in the class in order, data type and number. Arguments also do not have the data type listed in the call statement.
  6. This line is extremely important for learners to study. I once set all the password of their login's to this code, without any spaces, to force them to learn the code. It did cause havoc but at the end they all knew the code.
  7. Once the object has been instantiated you will not use TLearner again. From now on you will use Learner.MethodFromTheClass. For example: lblOutput.Caption := Learner.ToString;
  8. When you call any method that requires arguments, ensure that the arguments match the parameters of the method in: Order, number and data type.
  9. When calling Procedures they will stand on their own but remember a function has to be part of another statement / structure. For example: used in a condition, assigning a value to a variable or in output.
  10. Question 3.2.1 will typically instantiate the object. What learners need to keep in mind is that if Question 3.2.2 makes use of the object they always need to click on the button for Question 3.2.1 BEFORE they can click on the button Question 3.2.2 to instantiate the object before they try to use the other methods. A good example is in the exemplar of 2018 where the object is instantiated in Question 3.2.1 and then the testAge method of the class is called in Question 3.2.2.
  11. Common Errors when instantiating the object:
    • If they try to use a method of the class before they instantiated the object, as explained above, they will get a run time error containing "access violation" as part of the error. You are trying to access something that is not there yet.
    • If they placed the Constructor in the class under private they will get a syntax error "too many actual parameters". This is due to the main form not being able to see the Constructor and Delphi adding it's own default constructor, with no parameter, if you have not set one.
    • If they added the declaration of the class after implementation instead of between interface and implementation they will get a syntax error, "undeclared identifier TLearner" in the main form, highlighting the declaration of the object.
    • If they tried to instantiate the object using either of the following code TLearner.Create(sName,sDOB,rMark); OR Learner.Create(sName,sDOB,rMark); they will not get an access violation. The code will run but it will crash if you select the button in which you had this code. The run time error will also contain "access violation".
  12. Learners need to remember which methods were given or coded by themselves or even given in the class and use them where applicable in their program. For Example: If the learner were asked to count the number of A's of all the entries they should remember that an Accessor method was added in the class and use this method instead of declaring the input for the mark as global. if Learner.GetMark >= 80 then instead of if rMark >= 80 then
  13. I do one large example program with the learners. Once all the programs are working they then print the class and main form unit. We then highlight things code that are the same to help them understand and remember where to use what. For example highlighting the name of the Class under Type and then again in the main form under the declaration and where we instantiate the object.