我是个新手,求助各位大哥帮忙??
我用的是udpclient,udpserver两个组件,在uses里添加了winsock后,执行报错!!
源程序如上:
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Buttons,WinSock;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
Memo1: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations } end;
var
Form1: TForm1;
const
RECIEVETIMEOUT =5000;
type
TCommBlock = record
SenderName,
Msg :string[100];
end;
implementation{$R *.dfm}procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);///此行报错为[Error] Unit1.pas(28): Undeclared /////////////////////////////identifier: 'TIdSocketHandle'
var
Comm:TCommBlock;
begin
AData.ReadBuffer(Comm,AData.Size );
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
idudpclient1.Host:= edit1.Text;
idudpclient1.Port :=StrToInt(edit3.Text );
idudpclient1.ReceiveTimeout :=RECIEVETIMEOUT;
idudpserver1.DefaultPort:=StrToInt(edit4.Text);
idudpserver1.Active:=True;
BitBtn1.Enabled:=True;
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
Comm:TCommBlock;
begin
Comm.SenderName:= edit2.Text ;
Comm.Msg := edit5.Text ;
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
idudpclient1.SendBuffer(Comm,sizeof(Comm));
end;end.
回复EM:[email protected],兄弟先谢了!!!
我用的是udpclient,udpserver两个组件,在uses里添加了winsock后,执行报错!!
源程序如上:
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Buttons,WinSock;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
Memo1: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations } end;
var
Form1: TForm1;
const
RECIEVETIMEOUT =5000;
type
TCommBlock = record
SenderName,
Msg :string[100];
end;
implementation{$R *.dfm}procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);///此行报错为[Error] Unit1.pas(28): Undeclared /////////////////////////////identifier: 'TIdSocketHandle'
var
Comm:TCommBlock;
begin
AData.ReadBuffer(Comm,AData.Size );
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
idudpclient1.Host:= edit1.Text;
idudpclient1.Port :=StrToInt(edit3.Text );
idudpclient1.ReceiveTimeout :=RECIEVETIMEOUT;
idudpserver1.DefaultPort:=StrToInt(edit4.Text);
idudpserver1.Active:=True;
BitBtn1.Enabled:=True;
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
Comm:TCommBlock;
begin
Comm.SenderName:= edit2.Text ;
Comm.Msg := edit5.Text ;
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
idudpclient1.SendBuffer(Comm,sizeof(Comm));
end;end.
回复EM:[email protected],兄弟先谢了!!!
解决方案 »
- Delphi 如何给SQL中变量传值(急急急急)
- DELPHI中怎么把DBGrid所选的数据赋值给EDIT
- 要能生成POWER POINT的报表 用什么工具啊
- 在线等待..SOCKET
- 送分贴三:(讨论:根据数据库构造一棵树的最佳算法!版主与高手请进!)
- 版主和各位高手!窗体之间如何传递变量?我的思路和代码如下!不知何处错?
- 一个看似简单的问题:浮点数和字符串之间的转换?
- Table的Active与close、open
- 这是什么社会,能力至上!!!!!!
- 怎样写程序杀掉拨号进程rnaapp?不杀重拨时报'占线',事实上没占线,掉了才能拨上.
- 一个TDBGrid很菜的问题,进来看看把?
- ■■■■■■■■■■■你好,同志进来吧!!!(by ghyghost)
但是有的端口设置时报错::
could not bind socket,address and port is used!