unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ScktComp, Menus;type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    ClientSocket1: TClientSocket;
    connectitem1: TMenuItem;
    disconnect1: TMenuItem;
    exit1: TMenuItem;
    ServerSocket1: TServerSocket;
    Memo1: TMemo;
    Memo2: TMemo;
    listenitem1: TMenuItem;
    procedure listenitem1Click(Sender: TObject);
    procedure connectitem1Click(Sender: TObject);
    procedure Memo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);  private
    { Private declarations }
  public
    { Public declarations }  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.listenitem1Click(Sender: TObject); begin
 listenitem1.Checked:=not listenitem1.Checked;
  if listenitem1.Checked then
  begin
    clientsocket1.Active:=false;
    serversocket1.Active:=true;
  end
  else
  begin
    if serversocket1.Active then
      serversocket1.Active :=false;
  end;
end;
procedure TForm1.connectitem1Click(Sender: TObject);
var
my_server :string;
begin
 if clientsocket1.Active then clientsocket1.Active:=false;
 my_server :=inputbox('computer to connect to','address name:','');
 if my_server<>'' then
 begin
   with clientsocket1 do
   begin
   host:=my_server;
   active:=true;
   listenitem1.Checked:=false;
   end;//with clientsocket do
 end;//my_server<>'' then
end;procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key =vk_return then
if server then
serversocket1.socket.connections[0].sendText(Memo1.LineS[Memo1.LineS.Count - 1])
else
clientsocket1.socket.sendtext(Memo1.LineS[Memo1.LineS.Count -1]);end;   end.

解决方案 »

  1.   

     private
        { Private declarations }
      public
        { Public declarations }  end;var
      Form1: TForm1;implementation
       server:boolean;
    {$R *.dfm}如果在这儿申明错误提示更多,不知申明什么好。会的人能教教我吗?
      

  2.   

    你是要申明全局变量吗?
    private 
      { Private declarations } 
      server:boolean; //在这里声明私有变量
      public     
     { Public declarations }
      server:boolean; //在这里声明公共变量
     end; 
    var 
      Form1: TForm1; 
        server:boolean; //在这里声明全局变量
    implementation 
      

  3.   

    private
        { Private declarations }
      public
        { Public declarations }  end;var
      Form1: TForm1;implementation
      server:boolean;
    {$R *.dfm}如果在这儿申明错误提示更多,不知申明什么好。会的人能教教我吗?
    //这声明的只能在实现部分访问。其他单元不可方问题。
    //关键是你声明写错了,正确的应该为:var
      Form1: TForm1;implementationvar
      server:boolean;
      

  4.   

    SOCKET简单通信完整源代码下载: http://www.ahjoe.com/source/srcdown.asp