Hrmm. where to start..... OK here it goes.
My questions are:
4, Why isn't there a 'begin' statement?
because form1 is not the main application it is a unit used by the main application. Open your project inspector (menu project\project inspector) and double click the lpr file you will find your main application code there. Do not try to change it before researching what it does and how.
1. Where do I put procedures/functions which aren't event-handlers?. E.g. a function which is to be called from multiple event handlers. Do these functions need to be declared? and if so where?
Coming from a procedural background I would say that for now you declare them in the public section of the form class. That would be under
public
{ public declarations }
and before the end; That will give you access to everything you place on the form and make it a bit easier to start. as for the class section there are in total 4
Private, protected, public and published. The default section is published which means that the methods and objects declared in just below the TForm1 declaration are published and they should remain published. for now just use public for your own properties and methods until you find some use of the protected and private sections. The published section is only relevant to component writers you can leave with out it.
2. Do I put all global variables under the main var section?
No you do not! well, not quite, that is my opinion the fact is that a unit can have multiple var sections in between type and const sections there is no specific order for those 3 sections that it is required, you have to choose your own order. In general after the unit declaration comes the uses clause then a number of const, type and var sections, the implementation declaration, the implementation uses clause and the code for you procedures functions with a number of const, type or var sections in between.
As for the global part it is considered bad practise to use global variables, mainly because it is hard to track from where they get their values and why. So we usually tell people that they should never use global variables. In this case I'm guessing that you will have a single form for now, then add all your variables in a protected section in the tform1 class. As long as you place your procedures in the public section of tform1 you will have access to them. When the need arises for a second form ask again.
3. Where do I initialise variables?
Depends on the variables. If you follow my advice above then double click the form's background make sure you do not double click any control that covers the form completely and the IDE will create a onFormCreate event for you. This is called when the form is created and at that point the variables have their memory allocated and it is safe to initialize them. That been said every variable (known as field when declared inside a class) gets a default value by the compiler as a result of the process of allocating memory for the class (the memory allocated is zerod out) which helps for fast prototyping, regardless I always initialize key fields to the expected value to avoid problems down the road.
Always keep in mind that a class is the blueprint of an object and object is what exists in your memory at runtime.
to use a class you need to define a variable with its type eg
then you need to initialize the variable by calling the class constructor eg
Form1 := TForm1.Create(nil);
after you finished using it you need to free its memory by calling its destructor eg
form1.Free;//<-- method that checks for nil before calling the destructor.
That's it, have fun.