Weird array statement in loop.
- From: "Skybuck Flying" <BloodyShame@xxxxxxxxxxx>
- Date: Wed, 21 May 2008 03:59:25 +0200
Hello,
While coding I came across this programming mistake which was not detected
by the Delphi 2007 compiler.
I simply forgot to assign a value to vArray[Index] but the code still
compiled ?!
Demonstration:
// *** Begin of Weird Code ***
program Project1;
{$APPTYPE CONSOLE}
{
Test weird array statement in loop.
Version 0.01 created on 21 may 2008 by Skybuck Flying
Weird code which is allowed to compile just fine ?:
for vIndex := 0 to vSize-1 do
begin
vArray[vIndex]; // does nothing, why is this allowed ? Weird ?!
end;
No warning, no hint, no error, no nothing ?!?!?!
}
uses
SysUtils;
procedure Main;
var
vArray : array of byte;
vIndex : integer;
vSize : integer;
begin
vSize := 10;
SetLength( vArray, vSize );
for vIndex := 0 to vSize-1 do
begin
vArray[vIndex]; // does nothing, why is this allowed ? Weird ?!
end;
// display array to do something usefull with it
for vIndex := 0 to vSize-1 do
begin
write( vArray[vIndex] : 4 );
end;
writeln;
end;
begin
try
Main;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
readln;
end.
// *** End of Weird Code ***
Bye,
Skybuck
.
- Prev by Date: Re: Use pdf as background for form
- Next by Date: Re: Strange hint: Inline function 'DeleteFile' has not been expanded??
- Previous by thread: Strange hint: Inline function 'DeleteFile' has not been expanded??
- Next by thread: Delphi 6 to Delphi 2007
- Index(es):