• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking

Revision Master - starting the Delphi project

Before you start, create a folder for your project where you can keep all the files together and find them easily.  This is incredibly important and yet most people (including your teacher) forget to do it.  It saves a lot of time later.

Start a new VCL Project in Delphi.  VCL Stands for Visual Component library.

You'll be presented with an empty form.  You can run the program at this stage just to check that everything worked.  It won't do a lot, but it should run.

Picture

Add a memo field to the form so that you can see what's happening

Picture
This is a control that's just for us while we're developing the application.  When we've finished we'll remove it.  It helps us to see what's going on.

Now design your questions file

We're going to need a store of question and answer data.  When we're feeling confident, we'll use and Access Database - but for now we want to keep it simple, with just a basic text file.

How the text file works is up to you - but here's a suggestion.  Each line is a different question.  We can have as many lines as we want.  Each line therefore should contain the question, the possible answers and (because the program won't know) some information about which one of those is correct.

You can use notepad or Wordpad to create the question file.  The important thing is that it should be saved in plain text, without any funny characters, so that Delphi can read it.

Save the file in the top level of your N: drive so that you can find it easily.  You'll find that (if you use Notepad) it will have a .txt extension.
One idea ..
Picture
Another ..
Picture

What variables and arrays do you need?

You need to decide this soon.  Because you'll have basically a table of questions - and within that a number of possible answers, you're going to need Arrays.

Spend some time thinking about what you need, the names of any variables and arrays and how big they should be.

  • What is the maximum number of questions that you will have?
  • How many possible answers will there be?

A possible example is on the right.  Notice that the answers array is a special type of array that has two different indexes.  Why is that?


Click here for more on Arrays
var
  questions : Array[1..20] of string;
  answers : Array[1..20,1..5] of string;
  rightanswer : Array[1..20] of integer;
  numberofquestions : integer;



Now read each line from your question file into the program and display it

Picture
Delphi forms have a special procedure that automatically runs when the form is loaded (ie: when the program starts).  You'll use that to load the file at the beginning.

To find the procedure, double click on the form background.  It will take you to the editor and a procedure called 'FormCreate'.  It's got a peculiar parameter called 'Sender' which we can ignore for now.

Any code that you write in here will be run when the program starts.
Revise text files by looking again at the poem example we tried earlier

Once you have read the text from the file, make sure you have done it correctly by adding each line to the memo field.
Do this with the following line of Delphi:
  memo1.lines.Add(your string variable goes here) ;

Next step:  Breaking up the data into questions and answers

Powered by Create your own unique website with customizable templates.