procedure buttonclick();
var
aIdttcpclient:tIdttcpclient;
begin
aIdttcpClient:=TIdttcpclient.Create(nil);
with aIdttcpClient do
try
操作aIdttcpClient
......
finally
aIdttcpClient.free;
end;
end;
谢谢大侠。拜谢!试验成功
但是,我写下面的东西,比如我要调用它的onconnect事件,应该怎么调用呢?我用下面的方法,aIdttcpClientConnected没有执行?应该怎样调用控件的事件呢?
var
Form1: TForm1;
aIdttcpclient:TIdTCPClient;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
aIdttcpClient:=TIdTCPClient.Create(nil);
with aIdttcpClient do
aIdttcpClient.port:=9000;
aIdttcpClient.Connect();
end;
procedure TForm1.aIdttcpClientConnected(Sender: TObject);
begin
aIdttcpClient.Write('yhh');
end;
先写事件。
procedure ConnectedEvent(参数,注意和放一个控件的OnConnect参数相同,不知道可先放一个然后双击试一下,再记下来);
begin
......
end;
再在我给的代码中加上
procedure buttonclick();
var
aIdttcpclient:tIdttcpclient;
begin
aIdttcpClient:=TIdttcpclient.Create(nil);
with aIdttcpClient do
try
OnConnected:=ConnectedEvent;//加上这句
操作aIdttcpClient
......
finally
onConnected:=nil;
aIdttcpClient.free;
end;
end;
procedure ConnectedEvent(Sender: TObject);
begin
aIdttcpClient.Write('连接..........');
end;
procedure buttonclick();
var
aIdttcpclient:tIdttcpclient;
begin
aIdttcpClient:=TIdttcpclient.Create(nil);
with aIdttcpClient do
try
OnConnected:=ConnectedEvent;//加上这句
操作aIdttcpClient
......
finally
onConnected:=nil;
aIdttcpClient.free;
end;
end;