strange anomalies when using an iteration variable twice in 1 function



d4

I have 2 for to next loops in one function and find that in the second loop, using the iteration
variable to indicate array elements the first array element is used everytime.


in this example aEdit: ('1','0','0','0') type 'arrayofstring' self defined as 'array of string'
//=========================================================================
function Somefunction : variant;
var
i : integer;
aEdit : arrayofstring;
cTmp : string;
begin

//<snipped out some code here>

for i := low(aUservar) to high(aUservar) do begin
//..
end;


for i := low(aEdit) to high(aEdit) do begin
cTmp := aEdit[i];
result := hstrtoboolean(aEdit[i]); //<-testing compiler here
end;
end;
//=========================================================================

At iteration 1(as in i=1 whoever invented that counting should start at 0???) in loop 2 the compiler
would say that aEdit[i] = '0' but cTmp would be '1' and this valuable will be passed on to the
function hstrtoboolean.

If i add an integer variable 'k' to the function end replace all 'i' with 'k' in the second loop the
problem is over.

que?
.



Relevant Pages