当前位置:编程学习 > Delphi >>

delphi 中UDP 通讯问题。请高手指教!急!!!

程序如下,但是总是报错。错误内容在插图中,请高手务必帮小弟看看问题出在哪里。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Sockets, StdCtrls,ExtCtrls,IdUDPServer, IdSocketHandle,IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient; type TForm1 = class(TForm) GroupBox1: TGroupBox; GroupBox2: TGroupBox; ComboBox1: TComboBox; Memo1: TMemo; Memo2: TMemo; Button1: TButton; IdUDPClient1: TIdUDPClient; IdUDPServer1: TIdUDPServer; procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); procedure IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; AData: TBytes; ABinding: TIdSocketHandle); private { Private declarations } public { Public declarations } end; Tcommblock = record// sendername, msg :string[20];//消息,每次发送的消息的字节数 end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var comm: TCommBlock; begin comm.sendername:=combobox1.Text; comm.msg:=memo2.Text; memo1.Lines.Add(comm.sendername+':'+comm.msg); idudpclient1.SendBuffer(comm.msg,length(comm.msg)); end; procedure TForm1.FormShow(Sender: TObject); begin IdUDPClient1.Host:=''; IdUDPClient1.Port:=8080; IdUDPClient1.ReceiveTimeout:=5000; IdUDPClient1.Active:=true; end; procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; AData: TBytes; ABinding: TIdSocketHandle); var comm:TCommBlock; begin adata.Read(comm,adata.size); memo1.lines.Add(comm.sendername+':'+comm.msg); end; end.
答案:SendBuffer参数错了(你的用法是Indy9的,但后来的Delphi自带的是Indy10)
另外,TBytes是个数组,没有read的方法
其他:用D7来编译 

上一个:delphi dbgrid 排序
下一个:Delphi中如何对ComboBox下拉选项进行备注?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,