Delphi点击图像编码
我正在做一个项目,如果你按下一个图像,图像会导致另一个按钮通过编码按下 我尝试了Delphi点击图像编码,delphi,Delphi,我正在做一个项目,如果你按下一个图像,图像会导致另一个按钮通过编码按下 我尝试了Image.click,Image.OnClick:=Imageclick procedure TForm1.RandomRekenaar; var z: integer; begin z := 0; if (rgpSpelTipe.ItemIndex = 0) and (rgpSpelers.ItemIndex = 2) then begin z := Random(16 - 1 + 1);
Image.click
,Image.OnClick:=Imageclick代码>
procedure TForm1.RandomRekenaar;
var
z: integer;
begin
z := 0;
if (rgpSpelTipe.ItemIndex = 0) and (rgpSpelers.ItemIndex = 2) then
begin
z := Random(16 - 1 + 1);
case z of
1:
if Prent41.Visible <> False
then Prent41.OnClick := Prent41Click
else RandomRekenaar;
2:
begin
if Prent42.Visible <> False then
begin
Prent42.Click;
end
else
begin
RandomRekenaar;
end;
end;
3:
begin
if Prent43.Visible <> False then
begin
Prent43.Click;
end
else
begin
RandomRekenaar;
end;
end;
4:
begin
if Prent44.Visible <> False then
begin
Prent44.Click;
end
else
begin
RandomRekenaar;
end;
end;
5:
begin
if Prent45.Visible <> False then
begin
Prent45.Click;
end
else
begin
RandomRekenaar;
end;
end;
6:
begin
if Prent46.Visible <> False then
begin
Prent46.Click;
end
else
begin
RandomRekenaar;
end;
end;
7:
begin
if Prent47.Visible <> False then
begin
Prent47.Click;
end
else
begin
RandomRekenaar;
end;
end;
8:
begin
if Prent48.Visible <> False then
begin
Prent48.Click;
end
else
begin
RandomRekenaar;
end;
end;
9:
begin
if Prent49.Visible <> False then
begin
Prent49.Click;
end
else
begin
RandomRekenaar;
end;
end;
10:
begin
if Prent410.Visible <> False then
begin
Prent410.Click;
end
else
begin
RandomRekenaar;
end;
end;
11:
begin
if Prent411.Visible <> False then
begin
Prent411.Click;
end
else
begin
RandomRekenaar;
end;
end;
12:
begin
if Prent412.Visible <> False then
begin
Prent412.Click;
end
else
begin
RandomRekenaar;
end;
end;
13:
begin
if Prent413.Visible <> False then
begin
Prent413.Click;
end
else
begin
RandomRekenaar;
end;
end;
14:
begin
if Prent414.Visible <> False then
begin
Prent414.Click;
end
else
begin
RandomRekenaar;
end;
end;
15:
begin
if Prent415.Visible <> False then
begin
Prent415.Click;
end
else
begin
RandomRekenaar;
end;
end;
16:
begin
if Prent416.Visible <> False then
begin
Prent416.Click;
end
else
begin
RandomRekenaar;
end;
end;
end;
end;
end;
程序TForm1.RandomRekenaar;
变量
z:整数;
开始
z:=0;
如果(rgpSpelTipe.ItemIndex=0)和(rgpSpelers.ItemIndex=2),则
开始
z:=随机(16-1+1);
案例z
1:
如果Prent41.Visible False
然后Prent41.OnClick:=Prent41单击
雷克纳;
2:
开始
如果Prent42.Visible为False,则
开始
Prent42.单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
三:
开始
如果Prent43.Visible为False,则
开始
3.点击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
4:
开始
如果Prent44.Visible为False,则
开始
4.点击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
5:
开始
如果Prent45.Visible为False,则
开始
Prent45.单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
6:
开始
如果Prent46.Visible为False,则
开始
Prent46.单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
7:
开始
如果Prent47.Visible为False,则
开始
7.点击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
8:
开始
如果Prent48.Visible为False,则
开始
8.点击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
9:
开始
如果Prent49.Visible为False,则
开始
按一下;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
10:
开始
如果Prent410.Visible为False,则
开始
Prent410。单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
11:
开始
如果Prent411.Visible为False,则
开始
Prent411。单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
12:
开始
如果Prent412.Visible为False,则
开始
Prent412。单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
13:
开始
如果Prent413.Visible为False,则
开始
Prent413。单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
14:
开始
如果Prent414.Visible False,则
开始
Prent414.单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
15:
开始
如果Prent415.Visible为False,则
开始
Prent415.单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
16:
开始
如果Prent416.Visible为False,则
开始
Prent416。单击;
终止
其他的
开始
兰多姆雷克纳;
终止
终止
终止
终止
终止
您可以执行以下操作:
ImageClick(Image);
无论如何,我建议定义一个单独的函数:
procedure TForm1.SelectRandomImage();
begin
//...
end;
procedure TForm1.ImageClick(Sender : TObject);
begin
SelectRandomImage();
end;
通过这种方式,您可以直接调用SelectRandomImage
过程,我认为代码的可读性会更高。尝试类似以下内容:
var
图像:TImage的数组[0..15];
过程TForm1.FormCreate(发送方:TObject);
开始
图像[0]:=Prent41;
图像[1]:=Prent42;
...
图像[15]:=Prent416;
{或:
对于I:=0到15 do
图像[I]:=TImage(FindComponent('Prent4'+IntToStr(I+1));
}
终止
函数TForm1.RandomImage:TImage;
变量
VisibleMages:TImage的数组[0..15];
一、 计数:整数;
开始
结果:=无;
计数:=0;
对于I:=0到15 do
开始
如果图像[I]可见,则
开始
VisibleMages[计数]:=图像[I];
公司(计数);
终止
终止
如果计数>0,则
结果:=可见图像[随机(计数)];
终止
程序TForm1.RandomRekenaar;
变量
图片:TImage;
开始
如果(rgpSpelTipe.ItemIndex=0)和(rgpSpelers.ItemIndex=2),则
开始
图像:=随机图像;
如果图像为零,则
图像。单击;//或Image.OnClick(Image);
终止
终止
欢迎!请阅读此文,并将您编写的事件的详细信息放在一个过程中。此过程应生成一个随机数以选择randon图像。如果选择了图像,则图像应显示您是否阅读了Ajay提供的链接。您将发现,您需要提供您迄今为止尝试过的代码,无论它是否有效。代码需要用适当的变量声明以及函数、过程和方法声明和实现来演示这个问题。请回答您的问题并添加代码。您说:。。。如果推送图像…,但代码中没有图像。。。另按一个按钮…,但没有按钮。什么是Prent41
,Prent42
等。?Prent42.单击
(以及所有其他PrentXX.单击
)做什么?请详细解释一下。我重复一遍:代码需要用正确的变量声明以及函数、过程和方法声明和实现来演示这个问题。对于这样一个小程序,不需要编写这么多begin/end。它不起作用。@user11747134“它不起作用。”