我正在使用PingTool,並且我有一個TabSheet動態創建的按鈕(基於用戶輸入,從1-150的任何位置),我希望能夠通過OnClick命令給定TabSheet上的所有按鈕。我單獨的按鈕點擊成功運行我的ping代碼,但是當點擊我的PingAll按鈕時,我收到了EStackOverflow消息。任何幫助將不勝感激。代碼摘錄如下:用於按鈕創建發送OnClick命令到TabSheet上的所有動態TColorButtons
代碼:
begin
For x := 0 to CheckListBox1.Items.Count -1 Do
Begin
If CheckListBox1.Checked[x]=true then
begin
GLCount := (GLCount +1);
theIP :=(CheckListBox1.Items.Strings[x]);
if GLcount < 10 then begin
B := TColorButton.Create(Self);
B.Name:= ('BTN'+intToStr(GLCount+1));
B.Caption := theIP;
B.Parent := TabSheet2;
B.Height := 25;
B.Width := 97;
B.Left := 0 + GLCount * 96;
B.Top := 8;
B.BackColor := clBtnFace;
B.ForeColor := clBtnText;
B.OnClick := CustomButtonClick;
end;
CustomButtonClick代碼:
Procedure TForm1.CustomButtonClick(Sender: TObject);
begin
GlobalIP:=TColorButton(Sender).caption;
IdIcmpClient1.Host := GlobalIP;
IdIcmpClient1.ReceiveTimeout := 500;
IdIcmpClient1.Ping();
case IdIcmpClient1.ReplyStatus.ReplyStatusType of
rsEcho:
TColorButton(Sender).BackColor := clGreen;
rsTimeOut:
TColorButton(Sender).BackColor := clRed;
end;
end;
PingAll代碼(不工作):
procedure TForm1.PingAllClick(Sender: TObject);
var
i: integer;
begin
For i := 0 to TabSheet2.ControlCount -1 do
if TabSheet2.Controls[i] is TColorButton then
begin
TColorButton(Sender).Click;
end;
end;
您的表單中是否有IdAntiFreeze或類似組件? – jachguate
我不知道。不幸的是,我仍然非常青睞Delphi,而不是100%確定IdAntiFreeze的功能。我遇到的問題似乎與PingAll ButtonClick的處理有關,而不是實際執行的ping,因爲我的「CustomButtonClick」過程按預期的方式工作,點擊任何動態創建的按鈕 –