私はPingToolに取り組んでおり、動的に作成されたボタンのTabSheet(ユーザー入力に基づいて1〜150の任意の場所)があり、指定されたTabSheetのすべてのボタンにOnClickコマンドを渡せるようにしたいと考えています。個々のボタンをクリックするとpingコードが正常に実行されますが、PingAllボタンをクリックするとEStackOverflowメッセージが表示されます。どんな助けでも大歓迎です。以下のコードの抜粋:
ボタンの作成に使用されるコード:
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;