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

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

程序如下,但是总是报错。错误内容在插图中,请高手务必帮小弟看看问题出在哪里。 unit Unit1; inte易做图ce 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.
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,