Re: Re: strange anomalies when using an iteration variable twice in 1 function
- From: Hans Heintz <NOSPAMhh_000001@xxxxxxxxx>
- Date: Fri, 30 Sep 2005 08:19:47 +0200
On Thu, 29 Sep 2005 14:47:40 -0400, "Bruce Roberts" <ber@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>//=========================================================================
>>
>> 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.
>
What does hStrToBoolan matter if cTmp already has the wrong value?
My comment on counting isn't about for while loops but about arrays. I've tried defining arrays as
[1..10] for exampled but then dynamic arrays still start with 0 and if i pass an array through a
function inside the function the first element is 0 again so the mess only gets bigger.
Specially if you work with listviews I spent a lot of time thinking about ehhh the 3nd column so
that's subitem 1 because fist there's a caption and then there's the first subitem being subitem 0.
You get over it but it's just a waste of time.
There's just no logic to the first of something being 0. If there's some logic to the processor to
it it should be the compilers problem and not the programmers.
Sorry I'me prone to bold statements. Correct me if I'm wrong.
Here's hstrtoboolean and the whole function (already substituted i with k in the second loop):
//==============================================================================
function hstrtoboolean(const S : string): boolean;
begin
result := firstchar(tu(s)) in ['J','Y','T','1'];
end;
//==============================================================================
function GetUservars(cOmschrijf : string = 'Bewerken variabelen') : integer;
var
i,k : integer;
aPrefix : arrayofstring;
aTemplates : arrayofstring;
aWidth : arrayofinteger;
aEdit : arrayofstring;
aDefault : arrayofstring;
aHint : arrayofstring;
aSuffix : arrayofstring;
cTmp : string;
begin
aPrefix := nil;
aTemplates := nil;
aWidth := nil;
aEdit := nil;
aDefault := nil;
aHint := nil;
aSuffix := nil;
if length(uservars) > 0 then begin
for i := low(uservars) to high(uservars) do begin
with uservars[i] do begin
if (TimesUserinput = 0) then begin
if leeg(prefix) then aadd(aPrefix,varname) else aadd(aPrefix,prefix);
case vartype of
vtString : begin
aadd(aEdit,uservars[i].s);
aadd(aTemplates,'');
aadd(aWidth,40);
end;
vtDate : begin
aadd(aEdit,datetostr(uservars[i].d));
aadd(aTemplates,'DATE');
aadd(aWidth,40);
end;
vtReal : begin
aadd(aEdit,floattostr(uservars[i].r));
aadd(aTemplates,'FLOAT');
aadd(aWidth,40);
end;
vtInteger : begin
aadd(aEdit,floattostr(uservars[i].i));
aadd(aTemplates,'INT');
aadd(aWidth,40);
end;
vtBoolean : begin
if uservars[i].b then aadd(aEdit,'1') else aadd(aEdit,'0');
aadd(aTemplates,'CHECK,1,0');
aadd(aWidth,40);
end;
end;
end;
end;
end;
if (aEdit <> nil) then
result :=
GenVarEdit(aEdit,aPrefix,aEdit,aTemplates,aWidth,cOmschrijf,aHint,aSuffix,GVEEditVars)
else
result := mrcancel;
if result = mrok then begin
for k := 0 to high(uservars) do begin
with Uservars[k] do begin
cTmp := aEdit[k];
case vartype of
vtstring: s := aEdit[k];
vtdate: d := hstrtodate(aEdit[k]);
vtinteger: i := hstrtoint(aEdit[k]);
vtreal: r := hstrtofloat(aEdit[k]);
vtboolean: b := hstrtoboolean(aEdit[k]);
end;
inc(TimesUserinput);
end;
end;
end;
end;
end;
.
- Follow-Ups:
- Re: Re: strange anomalies when using an iteration variable twice in 1 function
- From: Maarten Wiltink
- Re: Re: strange anomalies when using an iteration variable twice in 1 function
- References:
- strange anomalies when using an iteration variable twice in 1 function
- From: Hans Heintz
- Re: strange anomalies when using an iteration variable twice in 1 function
- From: Bruce Roberts
- strange anomalies when using an iteration variable twice in 1 function
- Prev by Date: Re: Detecting Window
- Next by Date: Re: Detecting Window
- Previous by thread: Re: 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
|