Re: I suppose the idea of classes and inheritance is



J French wrote:

On Thu, 12 Oct 2006 11:19:47 -0700, Jamie
<jamie_ka1lpa_not_valid_after_ka1lpa_@xxxxxxxxxxx> wrote:

<snip>

While the String is 'terminated' with #0, attempting to get at that
index produces a Range Error if Range Checking is turned on.

procedure TForm1.Button1Click(Sender: TObject);
Var
S :String;
C :Char;
begin
{$R+}
S := StringOfChar('a', 10);
C := S[ Length( S ) + 1 ];
ShowMessage( IntToStr( Ord(C) ) );

end;


procedure TForm1.Button1Click(Sender: TObject);
var
S:String;
X:Integer;
C:char;
begin
C:= #$FF;
S := 'Test';
X := 5;
C := S[X];
if C = #0 then Beep;
end;
the above test does not generate a range error.
test your findings first please.


You have not got Range Checking turned on
- either turn it on via Project/Options or use {$R+} - then try running the code

IMO Range Checking should always be on by default, and only turned off
under very defined circumstances.

come on now, you think i am that numb to perform this test with
out turning on range testing?, take my word for it, it was on in the
test.
Learning how the compiler really does things helps a lot.

keep digging.

you did notice that i used a variable and not a constant to
index the string?
as long as your in the boundaries of the memory mapped for that
string, things just keep on computing happily..! range testing would
in volve the compiler to include the String Length function call to know
where the actual end of the string really is.. the last time i looked,
range checking performed checks of known entities of know size at compile time.
dynamically created objects like strings requires additional function
calls the be used in the code.
then of course, i am doing this in Win32 and not .Net or any other
make believe language.


--
Real Programmers Do things like this.
http://webpages.charter.net/jamie_5

.