while Px < image1.Width do begin ……; ……; Inc(Px, 10); end;
可是总是出错,我已经按照上面的方法做了,我该怎么办?[Error] Unit1.pas(42): Assignment to FOR-Loop variable 'px'
for px:=0 to image1.Width step 10 do begin ; ;end;
for px:=0 to image1.Width step=10 do begin ; ;end;你的变量 px 定义有问题么?
这种情况用while应该比较好吧 px:=0 while ps<image1.width do begin ^^^; px:=px+10; end
好象在VB中有For ... to ...Step ... do Statement这样的For语句。在Delphi里没有。如果要实现同样的效果,在期语句块中适当改变循环变量也是一种很好的方法。
循环里对循环变量赋值是不允许的!上面很多答案都错了! for px:=0 to 9 do begin //循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10 end;
循环里对循环变量赋值是不允许的!上面很多答案都错了! for px:=0 to (image1.Width div 10) do begin //循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10 end
For循环是一种比较严格的循环替,他的循环变量是由系统自动控制的,因此不允许 在循环体里改变循环变量. 这种情况下一般用 赋初值+while循环来解决. 当然在这里也可以将px和循环变量分开来处理 var LoopIndex : Integer ; for LoopIndex := 0 to image1.width div 10 do begin px := LoopIndex * 10 ; //如果嫌乘法太慢,可以用inc(px,10)来代替,不过别忘了给px赋初始值 .... end ;
循环里对循环变量赋值是不允许的!上面很多答案都错了! for px:=0 to (image1.Width div 10) do begin //循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10 end hxshanji(洪兴山鸡) ( ) 的方法对的..
begin
……;
……;
Inc(Px, 10);
end;
begin
;
;end;
begin
;
;end;你的变量 px 定义有问题么?
px:=0
while ps<image1.width do
begin
^^^;
px:=px+10;
end
for px:=0 to 9 do
begin
//循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10
end;
循环里对循环变量赋值是不允许的!上面很多答案都错了!
for px:=0 to (image1.Width div 10) do
begin
//循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10
end
在循环体里改变循环变量.
这种情况下一般用 赋初值+while循环来解决.
当然在这里也可以将px和循环变量分开来处理
var
LoopIndex : Integer ;
for LoopIndex := 0 to image1.width div 10 do
begin
px := LoopIndex * 10 ; //如果嫌乘法太慢,可以用inc(px,10)来代替,不过别忘了给px赋初始值
....
end ;
for px:=0 to (image1.Width div 10) do
begin
//循环利用到PX的地方用PX*10。这样PX每循环一次加1,PX*10就相当于加10
end
hxshanji(洪兴山鸡) ( ) 的方法对的..