Re: I suppose the idea of classes and inheritance is
- From: "Henry Bartlett" <hambar@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Oct 2006 17:49:41 +1100
"J French" <erewhon@xxxxxxxxxx> wrote
Please, Maarten, Alan, DoDi, Dr J would you test Jamie's example
and convince him that S[ Length(S) + 1 ] throws a range check
error with $R+ on a normal Delphi setup.
Well, if Delphi 2 is *not* a "normal Delphi setup" then you are
correct.
But in Delphi 2 (and perhaps in Delphi 3) S[ Length(S) + 1 ] does
not throw a range check error.
Even S[Length(S)+256] does not trigger a range check error in
Delphi 2.
I tested the following code in Delphi 1, Delphi 2 and Delphi 4 with
results as in the comments.
<CODE>
{ In D2 and D4, compiled with global range checking on AND off}
procedure TForm1.Button1Click(Sender: TObject);
Var S :String;
C :Char;
begin
{$R+}
S := 'aaaaaaaaaa'; {no StringOfChar in Delphi 1}
C := S[ Length( S ) + 1 ]; { RangeCheck Error in D4}
ShowMessage( IntToStr( Ord(C) ) );
{ in D1 shows 69 i.e. C = 'E' (random value)
in D2 Shows 0 i.e. C = #0
Does not get to here in D4}
{ Note: RANGE-CHECK MESSAGE IN D4 BUT NOT IN D1 OR D2}
{$R-}
end;
procedure TForm1.Button2Click(Sender: TObject);
var S:String;
X:Integer;
C:char;
begin
{$R+}
C:= #$FF; {Hint:..."Value assigned to C is never used"}
X := 5;
C := TestStr[X];
Label1.Caption := C;
{ RangeCheck Error in D4}
if C = #0 then
{$IfDef VER80} {Delphi 1}
MessageBeep(0);
{No beep in D1}
{$Else}
beep; { does not compile in D1}
{Beeps in D2}
{$Endif}
ShowMessage ( IntToStr( Ord(C) ) );
{ in D2 Shows 0 i.e. C = #0 but Does not get to here in D4}
{ Note: RANGE-CHECK MESSAGE IN D4 BUT NOT IN D1 OR D2}
//{$R-}
end;
</CODE>
Thus there is no String-length Range checking in Delphi 2.
Jamie once said:
i am using D3 and D7.
So if he tested in Delphi 3 (and not Delphi 7) its quite possible that
he got the results he reported.
It appears from this that Borland introduced String-length Range
checking in Delphi 4. This is quite reasonable as it protects against
access violations and I would prefer to see a Range-check error than
an AV.
Note that I get similar results to those of J French, Rob and Maarten
when I use Delphi 4.
--
Henry Bartlett
Delphi Links Page:
( http://www.hotkey.net.au/~hambar/habit/delflink.htm )
.
- Follow-Ups:
- Re: I suppose the idea of classes and inheritance is
- From: J French
- Re: I suppose the idea of classes and inheritance is
- References:
- I suppose the idea of classes and inheritance is
- From: Genome
- Re: I suppose the idea of classes and inheritance is
- From: Maarten Wiltink
- Re: I suppose the idea of classes and inheritance is
- From: Genome
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: Maarten Wiltink
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: J French
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: J French
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: J French
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: Rob Kennedy
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: J French
- Re: I suppose the idea of classes and inheritance is
- From: Jamie
- Re: I suppose the idea of classes and inheritance is
- From: J French
- I suppose the idea of classes and inheritance is
- Prev by Date: Re: I suppose the idea of classes and inheritance is
- Next by Date: Re: I suppose the idea of classes and inheritance is
- Previous by thread: Re: I suppose the idea of classes and inheritance is
- Next by thread: Re: I suppose the idea of classes and inheritance is
- Index(es):