i have following code example compiled in delphi xe5 update 2.
procedure TForm1.FormCreate(Sender: TObject);
var i,t:Integer;
buf: array [0..20] of TPair<Integer,Integer>;
begin
t := 0;
for i := Low(buf) to High(buf) do begin
ShowMessage(
Format(
'Pointer to i = %p;'#$d#$a+
'Pointer to buf[%d].Key = %p;'#$d#$a+
'Pointer to buf[%d].Value = %p;'#$d#$a+
'Pointer to t = %p',
[@i, i, @(buf[i].Key), i, @(buf[i].Value), @t]
)
);
buf[i].Key := 0;
buf[i].Value := 0;
t := t + 1;
end;
end;
if i run it it shows me the adresses of the variables.
the variables i
and t
have adresses in the memory range of buf
!
when i
reaches 3 the assignment buf[i].Value := 0;
overwrite first 3 bytes of i
and the last byte of t
. this results in a infinity loop because i
gets allways reset to 0
when it reaches 3
.
if i allocate the memory by myself with SetLength(buf,20);
everything is fine.
the picture shows what i mean.
my setup:
- Windows 7 64 Bit
- Delphi XE 5 Update 2
- Debug Configuration 32 Bit
strange, isn't it?
can anybody reproduce it?
is it a bug in the delphi compiler?
thanks.
EDIT:
here is the same example, but maybe better to understand what i mean:
and btw.: sorry for my bad english ;)