F
fs_zxyang
Unregistered / Unconfirmed
GUEST, unregistred user!
通过TcpServer接收来触发Timer OnTime事件无效,为什么!?!?
操作:
两个Button。
1是通过TcpClient发送消息,通过TcpServer接收来触发Button2Click;
2是直接触发Button2Click事件。
问题:执行Button1时,NewTimerOnTime无效;执行Button2正常。
请求高手帮助,谢谢!
代码如下:
var
Form1: TForm1;
aTimer: TTimer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
if TcpClient1.Connect then
TcpClient1.Sendln('Message');
finally
TcpClient1.Disconnect;
end;
end;
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s: string;
begin
// Add Order
s := ClientSocket.Receiveln;
while s <> ''do
begin
Memo1.Lines.Add(s);
Button2Click(nil);
s := ClientSocket.Receiveln;
end;
end;
procedure TForm1.NewTimerOnTime(Sender: TObject);
begin
Memo1.Lines.Add(TTimer(Sender).Name);
{当执行Button1时,此事件不能执行;当执行Button2时,此事件正常}
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
try
aTimer.Free;
except
end;
begin
aTimer := TTimer.Create(Self);
aTimer.Interval := 300;
aTimer.Name := 'NewTime0';
aTimer.OnTimer := NewTimerOnTime;
aTimer.Tag := 0;
aTimer.Enabled := True;
end;
Memo1.Lines.Add('Btn');
{<<==== 此处一切正常}
end;
操作:
两个Button。
1是通过TcpClient发送消息,通过TcpServer接收来触发Button2Click;
2是直接触发Button2Click事件。
问题:执行Button1时,NewTimerOnTime无效;执行Button2正常。
请求高手帮助,谢谢!
代码如下:
var
Form1: TForm1;
aTimer: TTimer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
if TcpClient1.Connect then
TcpClient1.Sendln('Message');
finally
TcpClient1.Disconnect;
end;
end;
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s: string;
begin
// Add Order
s := ClientSocket.Receiveln;
while s <> ''do
begin
Memo1.Lines.Add(s);
Button2Click(nil);
s := ClientSocket.Receiveln;
end;
end;
procedure TForm1.NewTimerOnTime(Sender: TObject);
begin
Memo1.Lines.Add(TTimer(Sender).Name);
{当执行Button1时,此事件不能执行;当执行Button2时,此事件正常}
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
try
aTimer.Free;
except
end;
begin
aTimer := TTimer.Create(Self);
aTimer.Interval := 300;
aTimer.Name := 'NewTime0';
aTimer.OnTimer := NewTimerOnTime;
aTimer.Tag := 0;
aTimer.Enabled := True;
end;
Memo1.Lines.Add('Btn');
{<<==== 此处一切正常}
end;