Re: strange anomalies when using an iteration variable twice in 1 function
- From: "Bruce Roberts" <ber@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 14:47:40 -0400
"Hans Heintz" <NOSPAMhh_000001@xxxxxxxxx> wrote in message
news:r5boj15s7n1iellmrso7tjc00euanldu0t@xxxxxxxxxx
> 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
> 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.
Can you provide at least the header for hStrToBoolean. If the routine isn't
too long, provide the whole thing. I would not be surprised if that routine
is at the root of the problem. I have thousands of lines of code in which
for loop control variables are reused, none of which display aberrant
behavior.
As to your comment on counting, for loop control variable values are
entirely under the control of the programmer. The Low function will return
the low bound of the array. If the array is defined as you described, then
Low (aEdit) will return zero. If the loop isn't starting with i = 0 then
arrayOfString is not defined the way you think it is. You may want to note
that there is a known "feature" of the debugger when displaying the value of
for loop control variables. You shouldn't trust the displayed value, it is
not always the actual value of the control variable.
.
- Follow-Ups:
- References:
- strange anomalies when using an iteration variable twice in 1 function
- From: Hans Heintz
- strange anomalies when using an iteration variable twice in 1 function
- Prev by Date: strange anomalies when using an iteration variable twice in 1 function
- Next by Date: Detecting Window
- Previous by thread: strange anomalies when using an iteration variable twice in 1 function
- Next by thread: Re: Re: strange anomalies when using an iteration variable twice in 1 function
- Index(es):
Relevant Pages
|