At this point you should be able to understand almost all of the following code:
unit UnitMain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, TypInfo;
//Constants
Const
MAX_PLAYERS = 10;
type
{ TFormMain }
TFormMain = class(TForm)
ButtonStart: TButton;
Memo: TMemo;
procedure ButtonStartClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
FormMain: TFormMain;
GlobalInteger : integer; //A global Variable declaration
implementation
{$R *.lfm}
{ TFormMain }
procedure DuplicateProcedure(v:integer);
var LocalResult:integer; //Local variable
begin
v:=2*v; //Local variable scope !
LocalResult:=v;
FormMain.Memo.Lines.Add('The procedure tells : The local result is :'
+ inttostr(LocalResult));
end;
function DuplicateFunction(v:integer):integer; //response
var LocalResult:integer; //Local variable
begin
v:=2*v; //Local variable scope !
LocalResult:=v;
result := LocalResult;
end;
procedure DuplicateProcedureGlobalVariable();
begin
GlobalInteger:=2*GlobalInteger;;
FormMain.Memo.Lines.Add('The procedure tells : The local result is :'
+ inttostr(GlobalInteger));
end;
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
//MAIN PROGRAM
procedure TFormMain.ButtonStartClick(Sender: TObject);
var LocalInteger : integer; //Local variables declarations
S1,S2 : string;
i : integer;
Players : array [1..9] of string; //Static array
UnlimitedPlayers : array of string; //Dynamic array
begin
//Comments/////////////////////////////////////////////////////////
//Comment single line
{
Comment
Multi line ...
}
//Constants!!!! ///////////////////////////////////////////////////
MAX_PLAYERS := 11;
//procedure call
DuplicateProcedure(11.4);
//function call
DuplicateFunction(MAX_PLAYERS);
end;
// Unit ending requires final pediod.
end.
Code will fall into error, to be honest the compiler will face two errors.
Before compiling and looking at Messages window to know them, try to catch them.
First must be immediate, second a bit less because we explained the reason not directly in the last few writing of previous page.
Try it yourself, and then compile.
Your new app will show the button, by clicking which you'll see a result in Memo.
This will be treated in next article, together with other stuff.
Have fun!