With the aspiring Game Programmer In Mind
By DragonPhinn [Howard N Smith]
This tutorial was designed for those fairly new to the Delphi environment. It's purpose is to familiarize you with the Delphi program, as well as show you how to use this compiler as a tool for building video games.
Load up your copy of Delphi and you will see a screen similar to this [depending on your version].
This program is broken down into four parts.
The toolbars/menu area houses all of the components and commands that you will need in the production of your program. It's fairly self explanitory.
DEFINITION: Components are controls that add functionality to your window. They include buttons, edit boxes, labels, and every other item you have ever seen on a window. You can view each of the controls your version of Delphi includes by viewing the upper bar on the menu space. Note: The words component and control can be used virtually interchangeably
The Forms area is the blank canvas, if you will, of your program. When you run your program this will be the window in which it will operate.
The Object Inspector shows all the properties of the selected component. These properties include color, caption, width, height, position, etc. They vary from control to control, but many share similar properties. If you take notice there is a second tab on the Object Inspector window. The second tab is called the "Events Tab"
On it are the various actions the selected control can perform. Some may include OnCreate, OnClick, OnMouseDown, etc. These are where you actually add functionality to the controls. Double click on the form to bring up the next section, which links to the Events tab.
This window is called the code view. By double clicking on most controls it brings you here to edit the default command. If you notice the default command of the Form is OnCreate. This is what the code should look like:
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
Lets take a look at the code. "procedure" means it is a command. TForm1.FormCreate is a function that says "when Form1 is created" then next part (Sender: TObject) is a variable passed that says who called the function. There are many useful ways to use this, for example, you can write a singe piece of code that is reused by numerous controls that refrences itself using the sender command.
The Begin and End statements surround your code.This is where we add commands, or instructions, for the program to execute when form1 is created. Type the following inbetween the begin and end statements:
ShowMessage('Hello World!');
Press F9, which means compile and run, and you will see a message box appear with the words "Hello World!" and an OK button. When you press the OK button, the window will appear.
Congradulations! You've created your first Delphi program! Every programmer, no matter how great, began with this humble beginning. You can take this moment to reflect on the glory of your own achivement.
So now you understand the very basics of programming with delphi. There is still a lot more to learn, but this should give you a solid start to work off of.
For more practice, try attaching the ShowMessage command to other events, such as a buttons OnClick, or a timers OnTimer. Play around with these functions to get a better understanding on how they work.
DragonPhinn