[Delphi]Błąd z portem


(Mr Hektor) #1

Witam, mam do napisania kółko i krzyżyk przez sieć. Działa na zasadzie p2p, nie ma osobnego serwera. Uruchamia się normalnie, działa też normalnie, ale właśnie tylko do pewnego momentu. Jak postawie kilka 'ixów' i kilka 'kółek' to obie aplikacje się sypią i wywala mi takie errory:

Wiem, że kod jest do bani, nieskładny i da się to napisać 100 razy wydajniej i krócej no ale cóż :wink:

Kod jednego:

unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, ScktComp;


type

  TForm1 = class(TForm)

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    Button4: TButton;

    Button5: TButton;

    Button6: TButton;

    Button7: TButton;

    Button8: TButton;

    Button9: TButton;

    RadioGroup1: TRadioGroup;

    ClientSocket1: TClientSocket;

    ServerSocket1: TServerSocket;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

    procedure Button6Click(Sender: TObject);

    procedure Button7Click(Sender: TObject);

    procedure Button8Click(Sender: TObject);

    procedure Button9Click(Sender: TObject);

    procedure ServerSocket1ClientRead(Sender: TObject;

      Socket: TCustomWinSocket);

    procedure RadioGroup1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('1X');

Button1.Caption := 'X';

Button1.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button2Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('2X');

Button2.Caption := 'X';

Button2.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button3Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('3X');

Button3.Caption := 'X';

Button3.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button4Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('4X');

Button4.Caption := 'X';

Button4.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button5Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('5X');

Button5.Caption := 'X';

Button5.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button6Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('6X');

Button6.Caption := 'X';

Button6.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button7Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('7X');

Button7.Caption := 'X';

Button7.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button8Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('8X');

Button8.Caption := 'X';

Button8.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button9Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('9X');

Button9.Caption := 'X';

Button9.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.ServerSocket1ClientRead(Sender: TObject;

  Socket: TCustomWinSocket);

var

  znak : string;

begin

znak := Socket.ReceiveText;

if znak = '1O' then

begin

Button1.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '2O' then

begin

Button2.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '3O' then

begin

Button3.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '4O' then

begin

Button4.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '5O' then

begin

Button5.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '6O' then

begin

Button6.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '7O' then

begin

Button7.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '8O' then

begin

Button8.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

if znak = '9O' then

begin

Button9.Caption := 'O';

RadioGroup1.ItemIndex := 0;

end;

end;


procedure TForm1.RadioGroup1Click(Sender: TObject);

begin

case RadioGroup1.ItemIndex of

0 :

begin

ServerSocket1.Active := False;

ClientSocket1.Active := True;

end;

1 :

begin

ClientSocket1.Active := False;

ServerSocket1.Active := True;

end;

end;


end;


end.

I drugiego:

unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, ExtCtrls, ScktComp;


type

  TForm1 = class(TForm)

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    Button4: TButton;

    Button5: TButton;

    Button6: TButton;

    Button7: TButton;

    Button8: TButton;

    Button9: TButton;

    RadioGroup1: TRadioGroup;

    ClientSocket1: TClientSocket;

    ServerSocket1: TServerSocket;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

    procedure Button6Click(Sender: TObject);

    procedure Button7Click(Sender: TObject);

    procedure Button8Click(Sender: TObject);

    procedure Button9Click(Sender: TObject);

    procedure ServerSocket1ClientRead(Sender: TObject;

      Socket: TCustomWinSocket);

    procedure RadioGroup1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('1O');

Button1.Caption := 'O';

Button1.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button2Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('2O');

Button2.Caption := 'O';

Button2.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button3Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('3O');

Button3.Caption := 'O';

Button3.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button4Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('4O');

Button4.Caption := 'O';

Button4.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button5Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('5O');

Button5.Caption := 'O';

Button5.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button6Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('6O');

Button6.Caption := 'O';

Button6.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button7Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('7O');

Button7.Caption := 'O';

Button7.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button8Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('8O');

Button8.Caption := 'O';

Button8.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.Button9Click(Sender: TObject);

begin

ClientSocket1.Socket.SendText('9O');

Button9.Caption := 'O';

Button9.Enabled := False;

RadioGroup1.ItemIndex := 1;

end;


procedure TForm1.ServerSocket1ClientRead(Sender: TObject;

  Socket: TCustomWinSocket);

var

  znak : string;

begin

znak := Socket.ReceiveText;

if znak = '1X' then

begin

Button1.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '2X' then

begin

Button2.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '3X' then

begin

Button3.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '4X' then

begin

Button4.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '5X' then

begin

Button5.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '6X' then

begin

Button6.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '7X' then

begin

Button7.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '8X' then

begin

Button8.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

if znak = '9X' then

begin

Button9.Caption := 'X';

RadioGroup1.ItemIndex := 0;

end;

end;


procedure TForm1.RadioGroup1Click(Sender: TObject);

begin

case RadioGroup1.ItemIndex of

0 :

begin

ServerSocket1.Active := False;

ClientSocket1.Active := True;

end;

1 :

begin

ClientSocket1.Active := False;

ServerSocket1.Active := True;

end;

end;


end;


end.