这样试试
procedure TForm1.Button1Click(Sender: TObject);
var mystream:tmemorystream;
tmpstr,computername:string;
i:integer;
begin
computername:='ddl';
listbox1.items.Add('ddl');
istbox1.ItemIndex:=0;
if edit1.text<>''
then
begin
nmudp1.ReportLevel:=status_basic;
nmudp1.localport:=8888;
nmudp1.remoteport:=8888;
if listbox1.items[listbox1.ItemIndex]=computername
then memo1.lines.add(computername+'say to himself'+edit1.text)
else memo1.lines.add(computername+'say to'+listbox1.Items[listbox1.itemindex]+edit1.text);
tmpstr:=edit1.text;
//mystream.create;
mystream :=TMemoryStream.Create;
//try
MyStream.Write(TmpStr,Length(Edit1.Text));
if listbox1.itemindex=0
then
begin
for i:=1 to listbox1.items.count-1 do
begin
nmudp1.remotehost:=listbox1.items[i];
nmudp1.sendstream(mystream);
end
end
else
begin
nmudp1.remotehost:=listbox1.Items[listbox1.itemindex];
nmudp1.sendstream(mystream);
end;
//finally
//mystream.free;
//end;
edit1.text:='';
edit1.setfocus;
end
else edit1.setfocus;
end;
procedure TForm1.Button1Click(Sender: TObject);
var mystream:tmemorystream;
tmpstr,computername:string;
i:integer;
begin
computername:='ddl';
listbox1.items.Add('ddl');
istbox1.ItemIndex:=0;
if edit1.text<>''
then
begin
nmudp1.ReportLevel:=status_basic;
nmudp1.localport:=8888;
nmudp1.remoteport:=8888;
if listbox1.items[listbox1.ItemIndex]=computername
then memo1.lines.add(computername+'say to himself'+edit1.text)
else memo1.lines.add(computername+'say to'+listbox1.Items[listbox1.itemindex]+edit1.text);
tmpstr:=edit1.text;
//mystream.create;
mystream :=TMemoryStream.Create;
//try
MyStream.Write(TmpStr,Length(Edit1.Text));
if listbox1.itemindex=0
then
begin
for i:=1 to listbox1.items.count-1 do
begin
nmudp1.remotehost:=listbox1.items[i];
nmudp1.sendstream(mystream);
end
end
else
begin
nmudp1.remotehost:=listbox1.Items[listbox1.itemindex];
nmudp1.sendstream(mystream);
end;
//finally
//mystream.free;
//end;
edit1.text:='';
edit1.setfocus;
end
else edit1.setfocus;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货