Why do I get an access violation when I call FillChar?
Consider my sample code:
var p512S开发者_运维技巧ector:PByte;
.....
getmem(p512Sector, 262144);
FillChar( p512Sector,262144 ,0);
When I run the program, Delphi gives me an violation access error. Why?
Use FillChar(p512Sector^, 262144, 0)
(note the dereferencing ^). Otherwise you are overwriting the pointer and the stuff behind in memory, not the allocated buffer.
FillChar
expects an untyped variable. You should dereference the pointer:
FillChar(p512Sector^, ...);
精彩评论