错误指向 Name:=$41;。错误提示为[Error] Unit1.pas(62): Incompatible types: 'Array' and 'Integer'
[Fatal Error] Project123.dpr(5): Could not compile used unit 'Unit1.pas'。
谁看看能改好它,跪谢。
源代码修改自http://www.qiqi8.cn/article/85/231/2007/2007090457130.html
各位大大们一定要帮忙啊请问如何修改,源程序如下
unit unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,NMUDP,ComCtrls,ExtCtrls, StdCtrls;type
tNetBiosNS = record
tID:word;
Flags:word;
Questions:word;
AnswerRRs:word;
AuthorityRRs:word;
AdditionalRRs:word;
Name:array [1..34] of byte;
tType:word;
tClass:word;
end;
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label4: TLabel;
Edit4: TEdit;
Button1: TButton;
NMUDP1: TNMUDP;
procedure NMUDP1DataSend(Sender: TObject);
procedure NMUDP1DataReceived(Sender: TComponent;NumberBytes: Integer; FromIP: String; Port: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}//发送“UDP-NetBIOS-NS”询问包
procedure TForm1.NMUDP1DataSend(Sender: TObject);
var
MyStream:TMemoryStream;
t_ns:tNetBiosNS;
i:byte;
begin
with t_ns do
begin
tID:=$0000;
Flags:=$1000;
Questions:=$0100;
AnswerRRs:=$0000;
AuthorityRRs:=$0000;
AdditionalRRs:=$0000;
Name[1]:=$20;
Name[2]:=$43;
Name[3]:=$4b;
for i:=4 to 33 do
Name:=$41;
Name[34]:=$00;
tType:=$2100;
tClass:=$0100;
end;
nmudp1.LocalPort:=3000;//UDP绑定的本地主机的端口
nmudp1.RemoteHost:=edit1.Text;
nmudp1.RemotePort:=137;// NetBIOS-NS ,137端口
MyStream:=TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream);
finally
MyStream.Free;
end;
end;//接收“UDP-NetBIOS-NS”应答包
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream:TMemoryStream;
mac_str:array[1..6]of byte;
NumOfNames:byte;
begin
if numberbytes>0 then //如果接收的数据包字节数>0,则处理数据包
begin
MyStream:=TmemoryStream.Create;
try
NMUDP1.readstream(MyStream); //把接收到的数据包,读到内存中
MyStream.Seek(56,SoFromBeginning);//定位至Number Of Names字段
MyStream.Read(NumOfNames,1); //获取 Number Of Names字段的值
MyStream.Seek(NumOfNames*18,soFromCurrent); //定位至Unit ID字段
MyStream.Read(mac_str[1],6); //获取Unit ID字段的值
edit4.Text:=inttohex(mac_str[1],2)+'-'+ //将目的主机的MAC地址格式化输出
inttohex(mac_str[2],2)+'-'+
inttohex(mac_str[3],2)+'-'+
inttohex(mac_str[4],2)+'-'+
inttohex(mac_str[5],2)+'-'+
inttohex(mac_str[6],2);
finally
MyStream.Free;
end;
end;
end;
end.
[Fatal Error] Project123.dpr(5): Could not compile used unit 'Unit1.pas'。
谁看看能改好它,跪谢。
源代码修改自http://www.qiqi8.cn/article/85/231/2007/2007090457130.html
各位大大们一定要帮忙啊请问如何修改,源程序如下
unit unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,NMUDP,ComCtrls,ExtCtrls, StdCtrls;type
tNetBiosNS = record
tID:word;
Flags:word;
Questions:word;
AnswerRRs:word;
AuthorityRRs:word;
AdditionalRRs:word;
Name:array [1..34] of byte;
tType:word;
tClass:word;
end;
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label4: TLabel;
Edit4: TEdit;
Button1: TButton;
NMUDP1: TNMUDP;
procedure NMUDP1DataSend(Sender: TObject);
procedure NMUDP1DataReceived(Sender: TComponent;NumberBytes: Integer; FromIP: String; Port: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}//发送“UDP-NetBIOS-NS”询问包
procedure TForm1.NMUDP1DataSend(Sender: TObject);
var
MyStream:TMemoryStream;
t_ns:tNetBiosNS;
i:byte;
begin
with t_ns do
begin
tID:=$0000;
Flags:=$1000;
Questions:=$0100;
AnswerRRs:=$0000;
AuthorityRRs:=$0000;
AdditionalRRs:=$0000;
Name[1]:=$20;
Name[2]:=$43;
Name[3]:=$4b;
for i:=4 to 33 do
Name:=$41;
Name[34]:=$00;
tType:=$2100;
tClass:=$0100;
end;
nmudp1.LocalPort:=3000;//UDP绑定的本地主机的端口
nmudp1.RemoteHost:=edit1.Text;
nmudp1.RemotePort:=137;// NetBIOS-NS ,137端口
MyStream:=TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream);
finally
MyStream.Free;
end;
end;//接收“UDP-NetBIOS-NS”应答包
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream:TMemoryStream;
mac_str:array[1..6]of byte;
NumOfNames:byte;
begin
if numberbytes>0 then //如果接收的数据包字节数>0,则处理数据包
begin
MyStream:=TmemoryStream.Create;
try
NMUDP1.readstream(MyStream); //把接收到的数据包,读到内存中
MyStream.Seek(56,SoFromBeginning);//定位至Number Of Names字段
MyStream.Read(NumOfNames,1); //获取 Number Of Names字段的值
MyStream.Seek(NumOfNames*18,soFromCurrent); //定位至Unit ID字段
MyStream.Read(mac_str[1],6); //获取Unit ID字段的值
edit4.Text:=inttohex(mac_str[1],2)+'-'+ //将目的主机的MAC地址格式化输出
inttohex(mac_str[2],2)+'-'+
inttohex(mac_str[3],2)+'-'+
inttohex(mac_str[4],2)+'-'+
inttohex(mac_str[5],2)+'-'+
inttohex(mac_str[6],2);
finally
MyStream.Free;
end;
end;
end;
end.
他们有的说Name:=$41改为Name[i]:=$41
但是改完以后打上IP,出现了堆栈溢出
Name:=$41;
改成:
for i:=4 to 33 do
Name[i]:=$41;
var
MyStream: TMemoryStream;
t_ns: tNetBiosNS;
i: byte;
begin
with t_ns do
begin
tID := $0000;
Flags := $1000;
Questions := $0100;
AnswerRRs := $0000;
AuthorityRRs := $0000;
AdditionalRRs := $0000;
Name[1] := $20;
Name[2] := $43;
Name[3] := $4B;
for i := 4 to 33 do
Name[i] := $41;
Name[34] := $00;
tType := $2100;
tClass := $0100;
end;
nmudp1.LocalPort := 3000; //UDP绑定的本地主机的端口
nmudp1.RemoteHost := edit1.Text;
nmudp1.RemotePort := 137; // NetBIOS-NS ,137端口
MyStream := TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream);//×××××××××递规触发了NMUDP1的OnDataSend事件!!!
finally
MyStream.Free;
end;
end;
在Button的OnClick事件中写procedure TForm1.Button1Click(Sender: TObject);
var
MyStream: TMemoryStream;
t_ns: tNetBiosNS;
i: byte;
begin
with t_ns do
begin
tID := $0000;
Flags := $1000;
Questions := $0100;
AnswerRRs := $0000;
AuthorityRRs := $0000;
AdditionalRRs := $0000;
Name[1] := $20;
Name[2] := $43;
Name[3] := $4B;
for i := 4 to 33 do
Name[i] := $41;
Name[34] := $00;
tType := $2100;
tClass := $0100;
end;
nmudp1.LocalPort := 3000; //UDP绑定的本地主机的端口
nmudp1.RemoteHost := edit1.Text;
nmudp1.RemotePort := 137; // NetBIOS-NS ,137端口
MyStream := TmemoryStream.Create;
try
MyStream.Write(t_ns, sizeof(t_ns));
NMUDP1.SendStream(MyStream);
finally
MyStream.Free;
end;
end;
nmudp1.LocalPort := 3000; //UDP绑定的本地主机的端口
nmudp1.RemoteHost := edit1.Text;
nmudp1.RemotePort := 137; // NetBIOS-NS ,137端口
我改成nmudp1.LocalPort := edit3.Text;
nmudp1.RemoteHost := edit1.Text;
nmudp1.RemotePort := edit2.Text;
为什么会出现
[Error] Unit2.pas(72): Incompatible types: 'Integer' and 'TCaption'
[Error] Unit2.pas(74): Incompatible types: 'Integer' and 'TCaption'
[Fatal Error] Project3.dpr(5): Could not compile used unit 'Unit2.pas'
能帮帮我吗,谢谢了
nmudp1.RemotePort := strtointdef(edit2.Text,0);
RemotePort那也填不上edit2,只有RemoteHOST能填上edit1.怎么办呢?