delphi 如何得到循环中满足条件的第一个值和最后一个值

2025-05-13 21:24:53
推荐回答(2个)
回答1:

var
GetFirst: boolean;
fiFristYValue,fiLastYValue: integer;
begin
.......
//之前的不写了,从这里开始
GetFirst:= false;
fiFristYValue := 0;
fiLastYValue := 0;
if (Hcor[x] >= Threshold) and (peakBegin = False) then
begin
if GetFirst then
begin
fiLastYValue := Y;
end
else
begin
fiFirstYValue := Y;
GetFirst := true;
end;
end;
end;
程序运行完,fiFirstYValue就是第一个满足条件的Y,fiLastYValue就是最后一个满足条件的Y值!

回答2:

var y1,y2:int;
y1=0;y2=0;
for y := 1 to FrameY do
for x := 1 to FrameX do
begin
if (Hcor[x] >= Threshold) and (peakBegin = False) then
begin
if y1=0 then y1:=y;
y2:=y;
end