|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 panshow 于 2016-8-26 08:39 编辑
我现在用的DELPHI XE10 版本。clientsocket 和serversocket 都集成到了scktcomp(下载的DELPHI7也没有clientsocket和serversocket)。以下是全部原代码
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.StdCtrls,
Vcl.DdeMan, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,scktcomp;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
ProgressBar1: TProgressBar;
Label8: TLabel;
Timer1: TTimer;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
ListBox1: TListBox;
procedure Panel2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Panel3Click(Sender: TObject);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
clientsocket1:Tclientsocket;
implementation
{$R *.dfm}
procedure TForm1.Panel1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.Panel2Click(Sender: TObject);
begin
if edit1.Text='' then
showmessage('Please enter a IP')
else if edit2.Text='' then
showmessage('Please enter a start port')
else if edit3.Text='' then
showmessage('Please enter a end port')
else if edit4.Text='' then
showmessage('Please enter a interval')
else
begin
if panel2.Caption='停止' then
begin
timer1.Enabled:=false;
clientsocket1.Port:=StrToInt(edit1.Text); //在这一步赋值时候出错了。
panel2.Caption:='扫描';
progressbar1.Step:=0;
edit1.Enabled:=true;
edit2.Enabled:=true;
edit3.Enabled:=true;
edit4.Enabled:=true;
panel2.Color:=clnavy;
panel3.Visible:=false;
end
else
begin
progressbar1.StepBy(-(StrToInt(edit3.Text)));
clientsocket1.Port:=StrToInt(edit2.Text);
listbox1.Items.Clear;
label7.Caption:=edit2.Text;
progressbar1.Min:=0;
progressbar1.Max:=(StrToInt(edit3.Text))-(StrToInt(edit2.Text));
timer1.Interval:=StrToInt(edit4.Text);
edit1.Enabled:=false;
edit2.Enabled:=false;
edit3.Enabled:=false;
edit4.Enabled:=false;
timer1.Enabled:=true;
panel2.Caption:='停止';
panel2.Color:=clred;
end;
end;
end;
procedure TForm1.Panel3Click(Sender: TObject);
begin
if panel3.Caption='恢复扫描' then
begin
timer1.Enabled:=true;
if timer1.Enabled =true then
begin
panel3.Caption:='暂停扫描';
panel3.Color:=clyellow;
end;
end
else
begin
Timer1.Enabled:=false;
panel3.Caption:='恢复扫描';
panel3.Color:=cllime;
progressbar1.Step:=0;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
s,d:integer;
//porty:string;
begin
if clientsocket1.Port=StrToInt(edit3.Text) then
begin
timer1.Enabled:=false;
panel2.Caption:='扫描';
edit1.Enabled:=true;
edit2.Enabled:=true;
edit3.Enabled:=true;
edit4.Enabled:=true;
panel2.Color:=clnavy;
panel3.Visible:=false;
showmessage('扫描完毕!');
end
else
begin
if clientsocket1.Port=StrToInt(label7.Caption) then
begin
d:=clientsocket1.Port+1;
label7.Caption:=IntToStr(d);
s:=StrToInt(label7.Caption);
//porty:=IntToStr(Tclientsocket); Tclientsocket.port无法调用
clientsocket1.Address:=edit1.Text;
clientsocket1.port:=s;
clientsocket1.open;
panel3.Visible:=true;
progressbar1.StepBy(1);
end;
end;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
begin
listbox1.Items.Add('Port'+IntToStr(clientsocket1.port));
if edit3.Text = label7.Caption then
begin
timer1.Enabled:=false;
end;
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
Timer1.Enabled:=true;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
end. |
|