Whillis, the approach you use is very inefficient, but I believe, you can start from this.
E.g. when a player pushes the button, you have a correct checking of "player" but you have to define the variable first in Var. Then you just have to switch player. e.g. in your code:
if (player=1) then
begin
Button2.Caption:=('X');
Player := 2;
end
else //<------------- this is important here
if (player=2) then
begin
Button2.Caption:=('O');
Player := 1;
end
Next you'll have to check for "win/loose" conditions. That'd be a bit more tricky. But, more importantly, you'll have to copy the code 9 times for every button.
That said, you'd better learn how procedures work. e.g. creating a
procedure MoveHere(aButton: TButton);
if (player=1) then
begin
aButton.Caption:=('X');
Player := 2;
end
else
begin
aButton.Caption:=('O');
Player := 1;
end;
if (Button1.Caption="X") and (Button2.Caption="X") and (Button3.Caption="X") then alert('Player X wins!!!');
if (Button4.Caption="X") and (Button5.Caption="X") and (Button6.Caption="X") then alert('Player X wins!!!');
... check all possible lines
//do the same for player O
if (Button1.Caption="O") and (Button2.Caption="O") and (Button3.Caption="O") then alert('Player O wins!!!');
... and check all possible lines again
...
...
procedure TForm2.Button4Click(Sender: TObject);
begin
MoveHere(Button4);
end;
This is still very inefficient, but it's easy to understand.
Once you've done with this way, try to generate the buttons
dynamically. With this you can automate creation, placement, operation of buttons and more efficiently checking for win conditions.